CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");
CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("en-US");
XmlLanaguage lang = XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag);
FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(lang));
FrameworkContentElement.LanguageProperty.OverrideMetadata(typeof(System.Windows.Documents.TextElement), new FrameworkPropertyMetadata(lang));
为了在一个文化中建立一个单一的线程,
Thread.CurrentThread.CurrentCulture = new CultureInfo("EN-US");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("EN-US");
FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(Markup.XmlLanguage.GetLanguage(Globalization.CultureInfo.CurrentCulture.IetfLanguageTag)));
public class CultureHelper : DependencyObject
{
public string Culture
{
get { return (string)GetValue(CultureProperty); }
set { SetValue(CultureProperty, value); }
}
// Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
public static readonly DependencyProperty CultureProperty =
DependencyProperty.RegisterAttached("Culture", typeof(string), typeof(CultureHelper), new FrameworkPropertyMetadata("en", CultureChanged));
private static void CultureChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
//For testing purposes in designer only
if (DesignerProperties.GetIsInDesignMode(d))
{
Thread.CurrentThread.CurrentUICulture = new CultureInfo((string)e.NewValue);
}
}
public static void SetCulture(DependencyObject element, string value)
{
element.SetValue(CultureProperty, value);
}
public static string GetCulture(DependencyObject element)
{
return (string)element.GetValue(CultureProperty);
}
}
5条答案
按热度按时间qcbq4gxm1#
没有办法为应用程序中的所有线程设置区域性,但是,如果您正在应用程序中创建线程,则可以如上所述自行为每个线程设置区域性
要将区域性设置为主应用程序,请使用以下代码段:
quhf5bfb2#
尝试把
.在您的csproj文件。
zynd9foi3#
好吧,这就是我用来确保我所有的应用程序都是在一个en-US文化。
为了在一个文化中建立一个单一的线程,
ttp71kqs4#
或者你可以试试这个:
7cjasjjr5#
或者尝试构建一个适当的Attached Property,如下所示