我正在创建一个WPF应用程序。它有两个使用相同静态字符串资源的标签,但有一些差异。例如,它有一个字符串资源,其中的密钥为string1
,值为SuccessRate
。我希望第一个标签为SuccessRate
,第二个Label
为SuccessRate(%)
。我定义与第一标签:wpf通过字符串操作将属性设置为静态资源
<Label Content="{StaticResource string1}" />
我如何定义第二Label
?
我正在创建一个WPF应用程序。它有两个使用相同静态字符串资源的标签,但有一些差异。例如,它有一个字符串资源,其中的密钥为string1
,值为SuccessRate
。我希望第一个标签为SuccessRate
,第二个Label
为SuccessRate(%)
。我定义与第一标签:wpf通过字符串操作将属性设置为静态资源
<Label Content="{StaticResource string1}" />
我如何定义第二Label
?
您可以使用ContentStringFormat
<Label Content="{StaticResource string1}" ContentStringFormat="{}{0}(%)" ... />
请注意,格式以{}
开头。这只是如果你的格式开始时必须在那里。 {
你可以在MSDN上阅读ContentStringFormat
。
Look [here](http://stackoverflow.com/questions/667511/binding-only-part-of-a-label) – nvoigt 2013-02-23 10:01:02