Wednesday, October 7, 2009

WPF: String Formatting in xaml

String can be Formatted very easily in xaml.
To format a text that is to be displayed in a textblock, first bind the textblock with the field and then use StringFormat attribute of the textblock to format the value.
For example:

<TextBlock Text="{Binding Children.Count}"/>

If you want to insert braces surrounding this value:
<TextBlock Text="{Binding Children.Count, StringFormat='{}{0:(#)}'}"/>


No comments: