WPF StringFormat={0:C} 显示为美元 [英] WPF StringFormat={0:C} showing as dollars

查看:32
本文介绍了WPF StringFormat={0:C} 显示为美元的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么会有这行代码

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

当我的所有区域设置都设置为英国时,将结果输出为 $xx.xx.我希望它输出为 £xx.xx.有任何想法吗?我尝试了字符串格式的不同变体,包括 StringFormat={}{0: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.

感谢您的关注.

推荐答案

我不确定这是否已在 .NET 4 中修复,但 WPF 在呈现货币或日期等内容时从未采用当前的文化.我认为这是一个很大的疏忽,但幸运的是很容易纠正.

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.

在您的应用类中:

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.

这篇关于WPF StringFormat={0:C} 显示为美元的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆