UWP change CalendarDatePicker language in runtime

依然范特西╮ 提交于 2019-12-19 04:20:16

问题


I have an application that changes UI in runtime. Here is my code for changing language:

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());
    }
}

All localization works fine, except CalendarDatePicker - it's Flyout doesn't get localized ( in runtime, when i relaunch the app - all if fine ).

Here are the examples

Opened a page and selected CalendarDatePicker:

Switched the language to Russian:

I have tried to do this:

// 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
}

And the result is this:

I have also tried to invalidate() everything. Also tried to trigger TemplateChild CalendarView Update method - no use. Any suggestions how to achieve normal language change?

EDIT:

Thanks to Elvis Xia, have been noticed that on language change in code, the CalendarView size gets screwed, because if i do this:

this.calendar.Language = "ru-RU"
this.calendar.Height = 500;
this.calendar.Width = 500;

I will get to see the dates ( screwed, but still ):

Any ideas how to fix this?


回答1:


So, as a dirty and nasty fix, i have set the CalendarView item height and width in XAML. Inside the CalendarDatePicker control template.

Width should be smaller than height at about 100px - the all works fine;

<CalendarView Height="400" Width="300" x:Name="CalendarView" ... />

But still this is not a solution



来源:https://stackoverflow.com/questions/40677814/uwp-change-calendardatepicker-language-in-runtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!