问题描述
我有一个基于印度的应用程序,我将文化设置为:
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.
如果我如下绑定一个 TextBox,它会显示 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.DefaultCulture
和 UserSettings.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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!