Saturday, 7 March 2009

Commar format in WPF

Add the following referencexmlns:sys="clr-namespace:System;assembly=mscorlib"Then add the following static resourceUserControl.Resourcessys:String x:Key="CommaFormat" {0:#,0} /sys:String...Then within the binding element of the Text use String FormatTextBlock Foreground="Black" Text="{Binding COVER, StringFormat={StaticResource CommaFormat}}" HorizontalAlignment="Right"/There is no way to directly add the string format into the Text propertyThe alternative using PropertyConverters requires a new class and therefore much more code than this...8Notes fromhttp://www.sloppycode.net/articles/formatstrings.aspxConsole.WriteLine("{0:g}", DateTimeKind.Utc); // generalConsole.WriteLine("{0:f}", DateTimeKind.Utc); // stringConsole.WriteLine("{0:d}", DateTimeKind.Utc); // integerConsole.WriteLine("{0:x}", DateTimeKind.Utc); // hex