如何使用冒号设置标签样式

All*_*lan 5 wpf xaml

我在WPF中有一个详细信息视图窗口,标签可能如下所示.

<Label Content="{x:Static properties:Resources.Reference}" />
Run Code Online (Sandbox Code Playgroud)

这是从我的属性Resource获取它的内容.

如何转换/格式化内容,使其在每个标签项后都有一个冒号.例如,而不是简单地显示参考的内容,我希望它转换为参考:

All*_*lan 19

我最终得到的解决方案是:

<Label Content="{x:Static properties:Resources.Reference}" ContentStringFormat="{}{0}:"/>
Run Code Online (Sandbox Code Playgroud)

  • 奇怪的是 - 这是我尝试过的早期解决方案之一,它不起作用?我后来发现有时'wysiwyg'窗口在我完全编译之前没有正确更新! (3认同)

Jul*_*ain 5

您可以使用Bindingwith StringFormat来格式化结果.

<Label Content="{Binding Source={x:Static properties:Resource.Reference}, StringFormat='{}{0}:'}"
Run Code Online (Sandbox Code Playgroud)

请注意,{}格式字符串之前是为了防止XAML解析器将其{0}视为标记扩展,{StaticResource}例如.