WPF - 绑定 StringFormatting 不起作用
我需要将一个简单的字符串附加到我的命令参数中,但不起作用。 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>
I need to append a simple string to my commandparameter but doesnt work. Does StringFormat support this or am I doing anything wrong ?
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
StringFormat 属性仅在目标属性的类型为字符串时才起作用。在本例中,目标属性是 CommandParameter,其类型为对象。您需要创建自己的 IValueConverter 并将其用作绑定的转换器。有一个类似于您需要的示例 IValueConverter IValueConverter 的 SL 文档。
The StringFormat property only works when the Type of the target property is string. In this case the target property is CommandParameter which is of type object. You'll need to create your own IValueConverter and use that as the Converter for your binding. There is an example IValueConverter similar to what you need in the SL docs for IValueConverter.