未使用默认 Resource.resx 文件
Default Resource.resx file not used
我有一个本地化的 WPF 应用程序。
当我从控制面板 -> 区域 -> 格式将格式设置为印地语(印度)时,在我的 WPF 应用程序开始启动时,我的 WPF 应用程序中的以下代码行未读取 CultureInfo.CurrentCulture(嗨-IN) 而不是使用 en-US。
Application.Current.MainWindow = new MainWindow();
Application.Current.MainWindow.Show();
因此,我的 WPF 应用程序未使用来自 Resources.resx 文件的问候消息。相反,它使用 Resources.en.resx
中的问候语
我在 CultureInfo.CurrentCulture
中得到了正确的值。
知道为什么上面的代码行没有选择正确的值吗?
ControlPanel->Region->Formats 设置不适用于 .resx 文件。在 ControlPanel->Region->Language 中指定默认语言。
What is the difference between CurrentCulture and CurrentUICulture properties of CultureInfo in .NET?
或者,您可以在 App
class (App.xaml.cs):
中指定资源的默认语言
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
Resources.Culture = System.Threading.Thread.CurrentThread.CurrentCulture;
}
}
我有一个本地化的 WPF 应用程序。
当我从控制面板 -> 区域 -> 格式将格式设置为印地语(印度)时,在我的 WPF 应用程序开始启动时,我的 WPF 应用程序中的以下代码行未读取 CultureInfo.CurrentCulture(嗨-IN) 而不是使用 en-US。
Application.Current.MainWindow = new MainWindow();
Application.Current.MainWindow.Show();
因此,我的 WPF 应用程序未使用来自 Resources.resx 文件的问候消息。相反,它使用 Resources.en.resx
中的问候语我在 CultureInfo.CurrentCulture
中得到了正确的值。
知道为什么上面的代码行没有选择正确的值吗?
ControlPanel->Region->Formats 设置不适用于 .resx 文件。在 ControlPanel->Region->Language 中指定默认语言。
What is the difference between CurrentCulture and CurrentUICulture properties of CultureInfo in .NET?
或者,您可以在 App
class (App.xaml.cs):
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
Resources.Culture = System.Threading.Thread.CurrentThread.CurrentCulture;
}
}