【问题标题】:UWP change CalendarDatePicker language in runtimeUWP 在运行时更改 CalendarDatePicker 语言
【发布时间】:2017-04-02 08:20:59
【问题描述】:

我有一个在运行时更改 UI 的应用程序。这是我更改语言的代码:

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

所有本地化工作正常,除了 CalendarDatePicker - 它的 Flyout 没有本地化(在运行时,当我重新启动应用程序时 - 一切正常)。

这里是例子

打开一个页面并选择 CalendarDatePicker:

将语言切换为俄语:

我已经尝试过这样做:

// 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 更新方法 - 没用。有什么建议如何实现正常的语言变化?

编辑:

感谢 Elvis Xia,已经注意到在代码中更改语言时,CalendarView 大小会被搞砸,因为如果我这样做:

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

我会看到日期(搞砸了,但仍然):

有什么办法解决这个问题吗?

【问题讨论】:

  • 从第二张图,你的意思是语言变了,但是日历弹出的大小有问题?
  • @ElvisXia-MSFT 我真的不能说这是一个大小问题。似乎日期部分没有呈现 - 或者你是对的,并且尺寸被破坏了。但是为什么如果我只更改了语言,而不是星期几 - 日期应该保持不变(理论上)
  • @ElvisXia-MSFT,你是对的,弹出窗口大小会发生一些奇怪的事情

标签: uwp uwp-xaml calendarview


【解决方案1】:

所以,作为一个肮脏和讨厌的修复,我在 XAML 中设置了 CalendarView 项目的高度和宽度。在 CalendarDatePicker 控件模板内。

宽度应该小于高度大约 100 像素 - 一切正常;

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

但这仍然不是解决方案

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-05
    • 1970-01-01
    • 1970-01-01
    • 2012-10-22
    • 1970-01-01
    • 2011-09-14
    • 2019-06-16
    相关资源
    最近更新 更多