Print the result as $...">

WPF StringFormat = {0: C} showing as dollars

Why is this line of code

<TextBlock Text="{Binding Net, StringFormat=c}"/> 

Print the result as $ xx.xx when all my regional settings are set in the UK. I expect him to print it as Β£ xx.xx. Any ideas? I have tried different variations of stringformat, including StringFormat = {} {0: C}, but still get the same result.

Thanks for watching.

+39
currency wpf binding string-formatting
May 04 '10 at 10:52 a.m.
source share
3 answers

I'm not sure if this was fixed in .NET 4, but WPF never raised the current culture when doing things like currency or dates. This is what I consider a huge oversight, but, fortunately, is easily fixed.

In your App class:

 protected override void OnStartup(StartupEventArgs e) { FrameworkElement.LanguageProperty.OverrideMetadata( typeof(FrameworkElement), new FrameworkPropertyMetadata( XmlLanguage.GetLanguage( CultureInfo.CurrentCulture.IetfLanguageTag))); base.OnStartup(e); } 

See this great post for more details.

+61
May 4 '10 at 11:03 a.m.
source share

I use Language = "en-GB" in the main window, for example.

 <Window x:Class="AllocateWPF.Vouchers" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Test" Height="692" Width="1000" Language="en-GB"> 
+18
Sep 23 '13 at 16:29
source share

What works for me:
1) In app.xaml, override OnStartup () and add - System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("et-EE");

2) Define at the XAML level @Window - xmlns:sysglb="clr-namespace:System.Globalization;assembly=mscorlib"

3) In XAML - <TextBox Text="{Binding Path=Price, StringFormat='{}{0:C}', ConverterCulture={x:Static sysglb:CultureInfo.CurrentUICulture}}" />

This one correctly selects the regional settings. . Although at the first stage I use the manually created CultureInfo, I am sure that you can pass one of the static types - for example. System.Globalization.CultureInfo.CurrentCulture (I have not tested it, though ...)

+13
Aug 24 '12 at 19:21
source share



All Articles