为什么 WPF 忽略我的 CultureInfo.CurrentCulture
Why WPF ignores my CultureInfo.CurrentCulture
我开始搞乱 MySQL.Data.EntityFramework (8.0.15),我的日期格式不对。
在我的文化 ('pl-PL') 中,日期格式是 "YYYY-MM-DD",但 DataGrid 默认以 "MM/DD/YYYY" 格式显示日期。我的 Windows 区域设置是正确的。
Console.WriteLine(CultureInfo.CurrentCulture); // shows pl-PL
我最初的绑定是这样的:
<!-- wrong date format -->
Binding="{Binding date}"
在绑定中设置 ConverterCulture 有效:
<!-- correct date format -->
{Binding date, ConverterCulture='pl-PL', StringFormat=d}
但是我不想到处设置 ConverterCulture。
我的问题是:
我该如何解决这个问题?
尝试设置
Thread.CurrentThread.CurrentUICulture
也许,你需要看看
FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(
XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
我开始搞乱 MySQL.Data.EntityFramework (8.0.15),我的日期格式不对。
在我的文化 ('pl-PL') 中,日期格式是 "YYYY-MM-DD",但 DataGrid 默认以 "MM/DD/YYYY" 格式显示日期。我的 Windows 区域设置是正确的。
Console.WriteLine(CultureInfo.CurrentCulture); // shows pl-PL
我最初的绑定是这样的:
<!-- wrong date format -->
Binding="{Binding date}"
在绑定中设置 ConverterCulture 有效:
<!-- correct date format -->
{Binding date, ConverterCulture='pl-PL', StringFormat=d}
但是我不想到处设置 ConverterCulture。
我的问题是:
我该如何解决这个问题?
尝试设置
Thread.CurrentThread.CurrentUICulture
也许,你需要看看
FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(
XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));