My problem is as follows: I have a datagrid that is bound to my datatable. I want a Button
to be placed in the row header, and I want the Button.Content
to display the concatenate of two strings. I have tried combining these two solutions: this and this
I have success with each individually, but combined it yields a blank Button.Content
. Here's what I've tried
<DataGrid.RowHeaderTemplate>
<DataTemplate>
<Button Width="90">
<Button.Content>
<MultiBinding StringFormat=" {0} - {1}">
<Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type DataGridRow}}" Path="Item.Index"/>
<Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type DataGridRow}}" Path="Item.Category"/>
</MultiBinding>
</Button.Content>
</Button>
</DataTemplate>
</DataGrid.RowHeaderTemplate
Any help would be appreciated.
Try adding TextBlock
and binding its Text
property:
<Button Width="90">
<Button.Content>
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat=" {0} - {1}">
<Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type DataGridRow}}" Path="Item.Index"/>
<Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type DataGridRow}}" Path="Item.Category"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</Button.Content>
</Button>
StringFormat
only applies if target is a string
property