0

我的问题如下:我有一个绑定到我的数据表的数据网格。我希望将 aButton放置在行标题中,并且希望Button.Content显示两个字符串的连接。我尝试将这两种解决方案结合起来:thisthis

我分别取得了成功,但结合起来会产生一个空白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

任何帮助,将不胜感激。

4

2 回答 2

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仅在目标是string属性时适用

于 2014-02-05T22:14:59.383 回答
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>
于 2014-02-05T22:43:45.750 回答