Eido95
Eido95

Reputation: 1383

How to format WPF StaticResource extension markup string value

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.

Upvotes: 0

Views: 459

Answers (1)

Hamlet Hakobyan
Hamlet Hakobyan

Reputation: 33381

You can use StringFormat property.

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

Upvotes: 3

Related Questions