开发者

How to style a label with a colon

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 开发者_Go百科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:


The solution I ended up with was:

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜