WPF Text StringFormat TextBlock
2 answers
Put it in resources as such and then access the format in the StringFormat
binding attribute .
<Page.Resources>
<system:String x:Key="InBracketsFormat">[{0}]</system:String>
</Page.Resources>
<TextBlock
Text="{Binding MyValue, StringFormat={StaticResource InBracketsFormat}}"/>
This technique provides the benefit of reuse as well as the ability to have text labels (such as a character '
) in the text for the format.
+2
source to share