How to create a colon shortcut

I have a detail view window in WPF, and the shortcut might look like this.

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

So, this gets its contents from my Resource.

How to convert / format content so that it has a colon after each label element. for example, instead of content just displaying the link, I want it to convert to a link:

+4
source share
2 answers

The solution I ended up with was:

 <Label Content="{x:Static properties:Resources.Reference}" ContentStringFormat="{}{0}:"/> 
+16
source

You can use Binding with StringFormat to format the result.

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

Note that the {} in front of the format string is here to prevent the XAML handler from processing {0} as a markup extension, such as {StaticResource} .

+4
source

Source: https://habr.com/ru/post/1309894/


All Articles