How to format WPF StaticResource extension markup string value

时间:2015-10-31 00:17:33

标签: wpf xaml

The following code example contains the usage of WPF StaticResource string value: <system:String x:Key="Sensor">Sensor</system:String> ... <TextBlock Text="{StaticResource Sensor}" TextAlignment="Center"/> What I need is to insert a + char before the "Sensor" string. (For example: + Senser) It is important to note that the usage of TextAlignment="Center" is necessary for me so replacing the TextBlcok with Label that uses HorizontalContentAlignmet="Center" is not an option, because my text is more than one line. Thanks.

1 个答案:

答案 0 :(得分:2)

您可以使用StringFormat属性。

<TextBlock Text="{Binding Source={StaticResource Sensor},
                          StringFormat={}+{0}}" TextAlignment="Center"/>
相关问题