Formating in WPF binding

Some time ago I wrote a post about how to format fields in a binding expression. It included the use of an IValueConverter to apply the format, now with .NET framework 3.5 SP1 that is not necessary anymore, because it  provides a new parameter in the binding expression called StringFormat that allow you to format any kind of fields:

<TextBlock Text="{Binding Text, StringFormat=The text is \'\{0\}\'}" />
<TextBlock Text="{Binding DateTime, StringFormat=\{0:d\}}" />
<TextBlock Text="{Binding DateTime, StringFormat=\{0:HH:mm:ss\}}" />

No Comments