如何格式化WPF StaticResource扩展标记字符串值
以下代码示例包含WPF如何格式化WPF StaticResource扩展标记字符串值,wpf,xaml,Wpf,Xaml,以下代码示例包含WPFStaticResourcestring值的用法: <system:String x:Key="Sensor">Sensor</system:String> ... <TextBlock Text="{StaticResource Sensor}" TextAlignment="Center"/> 传感器 ... 我需要的是在“Sensor”字符串之前插入一个+字符。(例如:+传感器) 需要注意的是,我需要使用TextAlignmen
StaticResource
string值的用法:
<system:String x:Key="Sensor">Sensor</system:String>
...
<TextBlock Text="{StaticResource Sensor}" TextAlignment="Center"/>
传感器
...
我需要的是在“Sensor”字符串之前插入一个+
字符。(例如:+传感器
)
需要注意的是,我需要使用TextAlignment=“Center”
,因此将TextBlcok
替换为使用HorizontalContentAlignmet=“Center”
的标签是不可取的,因为我的文本不止一行
谢谢。您可以使用属性
<TextBlock Text="{Binding Source={StaticResource Sensor},
StringFormat={}+{0}}" TextAlignment="Center"/>
非常感谢您提供如此快速简单的答案,您的答案完全符合我的需要!