c# - 覆盖语言后更改对话框的语言?
问题描述
我在 MainPage.cs 中的代码
ApplicationLanguages.PrimaryLanguageOverride = "ja-jp";
XAML
<Button content="Click" Click="Button_Click" />
在此之后,我用我的代码打开了对话框
private async void Button_Click(object sender, RoutedEventArgs e)
{
{
testDialog dialog = new testDialog();
await dialog.ShowAsync();
}
}
我的 testDialog 的 XAML 代码
<TextBlock x:Uid="TestTextBlock" />
我已经在 Resources.resw 文件中定义了语言的文本,如果我将文本块放在当前的 MainPage 中它工作正常,但是当我把它放在对话框中时,文本块的文本不会改变,它只会在我重置应用程序后改变。有什么想法可以解决这个问题吗?
解决方案
设置新语言:
Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = "ja-jp";
Windows.ApplicationModel.Resources.Core.ResourceContext.GetForCurrentView().Reset();
Windows.ApplicationModel.Resources.Core.ResourceContext.GetForViewIndependentUse().Reset();
重新加载当前页面:
private bool Reload(object param = null)
{
var type = Frame.CurrentSourcePageType;
try
{
return Frame.Navigate(type, param);
}
finally
{
Frame.BackStack.Remove(Frame.BackStack.Last());
}
}
您也可以Frame.Navigate(this.GetType());
用于刷新当前页面 UI。
请查看此帖子以获取更多信息:动态更改通用应用程序的语言
推荐阅读
- bazel - 使用 bazel genrule 添加外部依赖项失败并出现错误“没有输出的 Genrules 没有意义”
- ios - 原生到 React Native 调用
- spring-boot - 在 EC2 上启用 SSL 是否必须使用 Amazon Route 54?
- python - 从熊猫的字符串日期时间列中提取日期
- flutter - 在颤动中调整容器大小以精确到屏幕大小的一半
- javascript - 重置用于打印的 javascript 结果
- javascript - Visjs/React:动态构建数据集
- java - 错误:java:错误:无效的源版本:13 使用 JDK12 和 IntelliJ
- php - 我的代码出现数据库有什么问题?
- swift - MKPointAnnotation 到 MKMapItem