C# 在运行时更改ui语言

C# 在运行时更改ui语言,c#,resources,uwp,culture,C#,Resources,Uwp,Culture,我正在尝试动态更改我的UWP应用程序的ui语言。 除了包含语言组合框本身的页面之外,其他一切都可以正常工作 我必须从组合框中选择一种语言两次才能看到页面更改为另一种语言,为什么我必须这样做两次 private void comboUILanguages_SelectionChanged(object sender, SelectionChangedEventArgs e) { ResourceController.ChangeUILanguage((string)((ComboB

我正在尝试动态更改我的UWP应用程序的ui语言。 除了包含语言组合框本身的页面之外,其他一切都可以正常工作

我必须从组合框中选择一种语言两次才能看到页面更改为另一种语言,为什么我必须这样做两次

private void comboUILanguages_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
        ResourceController.ChangeUILanguage((string)((ComboBox)sender).SelectedItem);

        //for now, use a simple condition to determine wheter the page should be refreshed immediatly
        if (true)
        {
            MainPage.Current.RefreshMenu();
            Reload(currentGroup);
        }
}

private bool Reload(object param = null)
{
        var type = Frame.CurrentSourcePageType;

        try
        {
            return Frame.Navigate(type, param);
        }
        finally
        {
            Frame.BackStack.Remove(Frame.BackStack.Last());
        }
}
我的资源控制器:

class ResourceController
{
    private static ResourceLoader resourceLoader = ResourceLoader.GetForViewIndependentUse();

    public static string GetTranslation(string resource)
    {
        return resourceLoader.GetString(resource);
    }

    public static void ChangeUILanguage(string language)
    {
        Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = language;
        Windows.ApplicationModel.Resources.Core.ResourceContext.GetForViewIndependentUse().Reset();
    }

    public static string GetCurrentUILanguage()
    {
        return CultureInfo.CurrentUICulture.TwoLetterISOLanguageName; 
    }
}

初始化页面时,
组合框
中选择了哪个条目?可能您在重新加载时遇到问题,并在第一次重新加载后选择“旧”语言。或者这需要一些时间(试着睡100毫秒)。我不认为是后者,但你可以试试。它可以通过在构造函数中重置来解决。但我不知道为什么。如果需要一些时间,他们可能会创建一个异步方法,在初始化页面时设置PrimaryLanguageOverride,在
组合框中选择哪个条目?可能您在重新加载时遇到问题,并在第一次重新加载后选择“旧”语言。或者这需要一些时间(试着睡100毫秒)。我不认为是后者,但你可以试试。它可以通过在构造函数中重置来解决。但我不知道为什么。如果需要一些时间,他们可能会创建一个异步方法来设置PrimaryLanguageOverride