Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
wpf通过字符串操作将属性设置为静态资源_Wpf_Xaml_Resources_Label - Fatal编程技术网

wpf通过字符串操作将属性设置为静态资源

wpf通过字符串操作将属性设置为静态资源,wpf,xaml,resources,label,Wpf,Xaml,Resources,Label,我正在创建一个WPF应用程序。它有两个标签,它们使用相同的静态字符串资源,但有一些不同。例如,它有一个字符串资源,其键为string1,值为SuccessRate。我希望第一个标签是SuccessRate,第二个label是SuccessRate(%)。我使用以下内容定义第一个标签: <Label Content="{StaticResource string1}" /> 如何定义第二个标签?您可以使用两个元素将第二个标签的内容设置为a: <Label> &

我正在创建一个WPF应用程序。它有两个标签,它们使用相同的静态字符串资源,但有一些不同。例如,它有一个字符串资源,其键为
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