我有一个可以在运行时更改UI的应用程序。以下是更改语言的代码:
所有本地化功能都可以正常工作,除了日历日期选择器 - 它的弹出窗口无法本地化(在运行时,当我重新启动应用程序时 - 一切都好)。
以下是示例:
打开页面并选择日历日期选择器:
编辑: 感谢Elvis Xia提醒,注意到在代码中进行语言更改时,CalendarView的大小会出现问题,因为如果我这样做:
我可以帮你翻译成中文。这句话的意思是“我会看到日期(虽然可能有错误):”。
public void SwitchLanguage(SupportedLanguage language)
{
// Check if passed argument is different from current language
if (CurrentLanguage != language.Type)
{
// Set the new current language
CurrentLanguage = language.Type;
// Override tha application primary language ( it will automatically save the language preference )
Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = language.FourDigitCode;
ResourceContext.GetForViewIndependentUse().Reset();
ResourceContext.GetForCurrentView();
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("LocalizedResourceMap"));
// Notify code about the changes
this.LanguageChanged?.Invoke(this, new EventArgs());
}
}
所有本地化功能都可以正常工作,除了日历日期选择器 - 它的弹出窗口无法本地化(在运行时,当我重新启动应用程序时 - 一切都好)。
以下是示例:
打开页面并选择日历日期选择器:
将语言切换为俄语:
我尝试过这样做:
// Attach to LanguageChanged event - created in my own code
// And trigger this method inside CalendarDatePicker:
private void LanguageChanged(object sender, EventArgs e)
{
this.Language = "ru-RU"; // Hardcoded value for test only
}
结果就是这样:
我也尝试过invalidate()全部内容。还尝试触发TemplateChild CalendarView Update方法——没有用。有什么建议可以实现正常的语言更改吗?编辑: 感谢Elvis Xia提醒,注意到在代码中进行语言更改时,CalendarView的大小会出现问题,因为如果我这样做:
this.calendar.Language = "ru-RU"
this.calendar.Height = 500;
this.calendar.Width = 500;
我可以帮你翻译成中文。这句话的意思是“我会看到日期(虽然可能有错误):”。
有什么想法可以修复这个问题吗?