Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to style a label with a colon

Tags:

wpf

xaml

I have a details view window in WPF and a label may look like this.

<Label Content="{x:Static properties:Resources.Reference}" />

So that is obtains it content from my property Resource.

How can transform/format the content so it has a colon after each label item. e.g. instead of the content simply displaying Reference I want it to transform to Reference:

like image 633
Allan Avatar asked May 16 '10 06:05

Allan


2 Answers

The solution I ended up with was:

<Label Content="{x:Static properties:Resources.Reference}" ContentStringFormat="{}{0}:"/>
like image 76
Allan Avatar answered Oct 09 '22 19:10

Allan


You can use a Binding with StringFormat to format the result.

<Label Content="{Binding Source={x:Static properties:Resource.Reference}, StringFormat='{}{0}:'}"

Note that the {} before the format string is here to prevent the XAML parser from treating {0} as a markup extension, like {StaticResource} for example.

like image 39
Julien Lebosquain Avatar answered Oct 09 '22 19:10

Julien Lebosquain