StringFormat 被忽略 [英] StringFormat is ignored

查看:34
本文介绍了StringFormat 被忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


这是我的绑定(缩短了,Command-Property也绑定了)


This is my binding (shortened, Command-Property is also bound)

<MenuItem Header="Key" CommandParameter="{Binding StringFormat='Key: {0}', Path=PlacementTarget.Tag, RelativeSource={RelativeSource AncestorType=ContextMenu}}"/>

ContectMenu 的 PlacementTarget 的标签属性是一个类似字符串

The Tag-Property of ContectMenu's PlacementTarget is a String like

"Short.Plural"

我希望在命令处理程序中收到的是:

What i expect to receive in the Command-Handler is:

Key: Short.Plural

但我实际收到的是:

Short.Plural

推荐答案

Label 不使用 StringFormat,而是使用 ContentStringFormat.以这种方式使用它:

Label does not use StringFormat but ContentStringFormat. Use it this way:

<TextBlock x:Name="textBlock" Text="Base Text"/>
<Label Content="{Binding Path=Text, ElementName=textBlock}" ContentStringFormat="FORMATTED {0}"/>

这篇关于StringFormat 被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆