locked
Concatenate constant string with Binding in XAML RRS feed

  • Question

  • Hi,

    for the following code

    <DataGrid.RowHeaderTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor,
                                AncestorType={x:Type DataGridRow}},
                                Path=Item.BAD_COUNT}"
                        Foreground="Red"
                        ToolTip="{Binding RelativeSource={RelativeSource Mode=FindAncestor,
                                AncestorType={x:Type DataGridRow}},
                                Path=Item.BAD_NAMES}"
             />
        </DataTemplate>
    </DataGrid.RowHeaderTemplate>

    I want the tooltip to show the string "Bad Names : " + the binding value (Item.BAD_NAMES)

    How can I do this using StringFormat and not have to rely on custom coded converters?

    Thanks,

    -sri

    sri

    Thursday, April 18, 2013 3:28 AM

Answers

  • Hi, Give this a go (I've not tried it on your DataTemplate but it normally works for me).

    <TextBlock Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, 
                        AncestorType={x:Type DataGridRow}}, 
                        Path=Item.BAD_COUNT}"
                Foreground="Red">
        <TextBlock.ToolTip>
            <ToolTip Content="{Binding RelativeSource={RelativeSource Mode=FindAncestor, 
                        AncestorType={x:Type DataGridRow}}, 
                        Path=Item.BAD_NAMES}" ContentStringFormat="{}Bad Names: {0}"/>
        </TextBlock.ToolTip>
    </TextBlock>

    • Marked as answer by Min Zhu Monday, April 22, 2013 3:17 AM
    Thursday, April 18, 2013 3:53 AM