views:

342

answers:

1

Why does this line of code

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

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

Thanks for looking.

+5  A: 

I'm not sure if this has been fixed in .NET 4, but WPF has never picked up the current culture when rendering things like currency or dates. It's something I consider a massive oversight, but thankfully is easily corrected.

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 excellent post for more information.

Matt Hamilton
Perfect, I spent an hour trying to find a solution and you solved it in 5 minutes, thank you.
Coesy
Actually, according to [this bug report at MS Connect](https://connect.microsoft.com/VisualStudio/feedback/details/442569/wpf-binding-uses-the-wrong-currentculture-by-default), it is not a bug, but a *feature* as MS states... Pretty weird *feature*, I would say, but it might be good to know that this is unlikely to be "fixed" in a future version.
gehho