的StringFormat被忽略 [英] StringFormat is ignored

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

问题描述



这是我结合(缩短,命令属性也必然)

 <菜单项标题=密钥CommandParameter ={绑定的StringFormat ='键:{0},路径= PlacementTarget.Tag,的RelativeSource = {的RelativeSource AncestorType =文本菜单}} />

ContectM​​enu的PlacementTarget的Tag-属性类似于

一个String

 Short.Plural

我所期望获得的命令处理程序是:

 键:Short.Plural

但我实际上可以得到的是:

  Short.Plural


解决方案

标签不使用的StringFormat但ContentStringFormat。使用这种方式:

 < TextBlock的X:名称=TextBlock的文本=基础文本/>
<标签内容={绑定路径=文字的ElementName =文本块}ContentStringFormat =FORMATTED {0}/>


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}}"/>

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

But what i acutally receive is:

Short.Plural

解决方案

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天全站免登陆