WPF - 绑定StringFormatting无效

3

我需要将一个简单的字符串附加到我的命令参数上,但不起作用。StringFormat 支持这个吗?还是我做错了什么?

  <DataTemplate x:Key="ClickableHeaderTemplate">
              <Button x:Name="btn" Content="{Binding}" Background="Transparent"
                  Command="{Binding DrilldownHeaderClicked}" 
                     Tag="{Binding RelativeSource={RelativeSource Self}, Path=Content}"
                     CommandParameter="{Binding RelativeSource={RelativeSource Self}, Path=Tag, StringFormat=somestring\{0\}}"> --- formatting doesnt work. tried without escape seq as well as in 'somesting{0}'. 
                 </Button>
            </DataTemplate>
1个回答

4

StringFormat属性仅适用于目标属性的类型为字符串的情况。在本例中,目标属性是类型为object的CommandParameter。您需要创建自己的IValueConverter并将其用作绑定的转换器。在IValueConverter的SL文档中有一个类似于您所需的示例IValueConverter。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接