wpf通过字符串操作将属性设置为静态资源
我正在创建一个WPF应用程序。它有两个标签,它们使用相同的静态字符串资源,但有一些不同。例如,它有一个字符串资源,其键为wpf通过字符串操作将属性设置为静态资源,wpf,xaml,resources,label,Wpf,Xaml,Resources,Label,我正在创建一个WPF应用程序。它有两个标签,它们使用相同的静态字符串资源,但有一些不同。例如,它有一个字符串资源,其键为string1,值为SuccessRate。我希望第一个标签是SuccessRate,第二个label是SuccessRate(%)。我使用以下内容定义第一个标签: <Label Content="{StaticResource string1}" /> 如何定义第二个标签?您可以使用两个元素将第二个标签的内容设置为a: <Label> &
string1
,值为SuccessRate
。我希望第一个标签是SuccessRate
,第二个label
是SuccessRate(%)
。我使用以下内容定义第一个标签:
<Label Content="{StaticResource string1}" />
如何定义第二个
标签
?您可以使用两个元素将第二个标签的内容
设置为a:
<Label>
<TextBlock>
<Run Text="{StaticResource string1}"/>
<Run Text="(%)"/>
</TextBlock>
</Label>
也许您只需要文本块而不需要标签:
<TextBlock Text="{StaticResource string1}"/>
<TextBlock>
<Run Text="{StaticResource string1}"/>
<Run Text="(%)"/>
</TextBlock>
您可以使用
ContentStringFormat
<Label Content="{StaticResource string1}" ContentStringFormat="{}{0}(%)" ... />
请注意,格式以{}
开头。如果你的格式是从<代码>{
您可以在上阅读ContentStringFormat
。Look