我有一个基于印度的应用程序,并且将Culture设置为:
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-IN");
上面的代码在调用Window.InitializeComponent()方法之前被调用。
Window.InitializeComponent()
仍然$在所有TextBox中显示为CurrencySymbol。
$
如果我按如下所示绑定文本框,它将显示Rs.为CurrencySymbol:
Rs.
Text="{Binding Salary,Mode=TwoWay,StringFormat=C,ConvertCulture=en-IN}".
我认为您将需要添加以下内容。
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
仅举一个例子,这就是我基于用户设置在程序中初始化Culture的方式,但是您可以简单地用所需的Culture 替换UserSettings.DefaultCulture和UserSettings.Default.UICultrue。
UserSettings.DefaultCulture
UserSettings.Default.UICultrue
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))); }