我的问题如下:我有一个绑定到我的数据表的数据网格。我希望Button
放在行标题中,我希望Button.Content
显示两个字符串的连接。我尝试将这两种解决方案结合起来:this和this
我个人成功,但结合起来会产生空白Button.Content
。这是我试过的
<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
任何帮助将不胜感激。
答案 0 :(得分:0)
尝试添加TextBlock
并绑定其Text
属性:
<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
仅适用于target为string
属性
答案 1 :(得分:0)
我认为您的StringFormat语法错误:尝试:
<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>