在WPF应用程序中全局设置文化(en-IN) [英] Setting Culture (en-IN) globally in WPF application

查看:144
本文介绍了在WPF应用程序中全局设置文化(en-IN)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,该应用程序基于印度,并且将文化"设置为:

I have an application, which is based for India, and I'm setting Culture as:

Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-IN");

上面的代码在调用Window.InitializeComponent()方法之前被调用.

The above code is called before the Window.InitializeComponent() method is called.

仍然在所有文本框中将$显示为CurrencySymbol.

Still this is showing $ as CurrencySymbol in all TextBoxes.

如果按以下方式绑定文本框,则它将Rs.显示为CurrencySymbol:

If I bind a TextBox as following, it shows Rs. as CurrencySymbol:

Text="{Binding Salary,Mode=TwoWay,StringFormat=C,ConvertCulture=en-IN}".

推荐答案

我认为您需要添加以下内容.

I think you will need to add the following.

Thread.CurrentThread.CurrentCulture = new CultureInfo("en-IN");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-IN");
FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(
            XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));

在此处阅读更多信息:

http://www.west-wind.com/weblog/posts/2009/Jun/14/WPF-Bindings-and-CurrentCulture-Formatting

仅举一个例子,这就是我根据用户设置在程序中初始化文化的方式,但是您可以简单地将UserSettings.DefaultCultureUserSettings.Default.UICultrue替换为所需的文化.

Just to give you an example, this is how I initialize the Culture in my program, based on the user setting, but you can simply replace UserSettings.DefaultCulture and UserSettings.Default.UICultrue with your wanted Culture.

private static void InitializeCultures()
{
    if (!String.IsNullOrEmpty(UserSettings.Default.Culture))
    {
        Thread.CurrentThread.CurrentCulture = new CultureInfo(UserSettings.Default.Culture);
    }
    if (!String.IsNullOrEmpty(UserSettings.Default.UICulture))
    {
        Thread.CurrentThread.CurrentUICulture = new CultureInfo(UserSettings.Default.UICulture);
    }

    FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(
        XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
}

这篇关于在WPF应用程序中全局设置文化(en-IN)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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