2013-02-23 67 views
1

我正在创建一个WPF应用程序。它有两个使用相同静态字符串资源的标签,但有一些差异。例如,它有一个字符串资源,其中的密钥为string1,值为SuccessRate。我希望第一个标签为SuccessRate,第二个LabelSuccessRate(%)。我定义与第一标签:wpf通过字符串操作将属性设置为静态资源

<Label Content="{StaticResource string1}" /> 

我如何定义第二Label

+1

Look [here](http://stackoverflow.com/questions/667511/binding-only-part-of-a-label) – nvoigt 2013-02-23 10:01:02

回答

0

您可以设置第二个标签的ContentTextBlock有两个Run元素:

<Label> 
    <TextBlock> 
     <Run Text="{StaticResource string1}"/> 
     <Run Text="(%)"/> 
    </TextBlock> 
</Label> 

也许你需要有唯一的TextBlocks,而不是标签反正:

<TextBlock Text="{StaticResource string1}"/> 
<TextBlock> 
    <Run Text="{StaticResource string1}"/> 
    <Run Text="(%)"/> 
</TextBlock> 
0

您可以使用ContentStringFormat

<Label Content="{StaticResource string1}" ContentStringFormat="{}{0}(%)" ... /> 

请注意,格式以{}开头。这只是如果你的格式开始时必须在那里。 {

你可以在MSDN上阅读ContentStringFormat