将文本附加到静态资源

Ton*_*Nam 6 wpf xaml string-formatting staticresource

如果我有标签:

<Label Content="{StaticResource Foo}" />
Run Code Online (Sandbox Code Playgroud)

有没有办法在xaml中附加*?

我正在寻找类似的东西:

<Label Content="{StaticResource Foo, stringformat={0}*" />
Run Code Online (Sandbox Code Playgroud)

我从资源字典中放置控件的内容,因为该应用程序支持多种语言.我想知道是否可以在xaml中附加*,这样我就不必创建一个事件,然后在事件触发时附加它.

编辑:

在资源字典中,我有:

 <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:system="clr-namespace:System;assembly=mscorlib"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                >

     <system:String x:Key="Foo">Name</system:String>

 </ResourceDictionary>
Run Code Online (Sandbox Code Playgroud)

在我的窗口我有:(我合并了最后一本字典)

  <Label Content="{StaticResource 'Foo'}" />
Run Code Online (Sandbox Code Playgroud)

并显示名称

我希望标签显示Name*而不仅仅是Name

也许有可能通过一种风格实现这一目标.

nem*_*esv 12

有多种方法可以做到:

  1. 使用ContentStringFormat:

    <Label Content="{StaticResource Foo}" ContentStringFormat='{}{0}*'/>
    
    Run Code Online (Sandbox Code Playgroud)
  2. 使用StringFormat绑定(它只适用于字符串属性,这就是为什么你需要使用a TextBlock作为Label内容)

    <Label>
       <TextBlock 
           Text="{Binding Source={StaticResource Foo}, StringFormat='{}{0}*'}"/>
    </Label>
    
    Run Code Online (Sandbox Code Playgroud)
  3. 或者你可以写一个转换器来追加*