Skip to content

ApplicationLanguages.PrimaryLanguageOverride doesn't update x:Uid without restarting the appΒ #5940

@YegorStepanov

Description

@YegorStepanov

Describe the bug
After setting ApplicationLanguages.PrimaryLanguageOverride, the new pages use old x:Uid. Restart only refresh it. The code below updates x:Uid in UWP but doesn't in WinUI.

The following sub-links also don't solve the problem:
UWP - Change of Languages

Are in WinUI the way to update x:Uid in runtime without manually updating strings in response to qualifier value change events?

Steps to reproduce the bug
Steps to reproduce the behavior:

  1. Add "Hello.Text" to Strings/en/Resources.resw and to Strings/ru/Resources.resw
  2. Assign x:Uid to TextBlock
  3. Copy templated UWP code from OnLaunched and eliminate the errors (base.Frame is null by default in WinUI)
  4. Add handler to button:
private void myButton_Click(object sender, RoutedEventArgs e)
{
    string lang = ApplicationLanguages.PrimaryLanguageOverride is "en" ? "ru" : "en";
    ApplicationLanguages.PrimaryLanguageOverride = lang;
        
    ResourceContext.GetForViewIndependentUse().Reset();
    
    Frame.Navigate(typeof(MainPage)); //old
    
    new Window { Content = new MainPage() }.Activate(); //old

    //it works, but not in XAML
    string newLanguage = ResourceLoader.GetForViewIndependentUse().GetString("Hello/Text");
}

Expected behavior
The newly created Page/Window has the desired localizated x:Uid.

Version Info
[WinUI 3 - Windows App SDK 0.8: 0.8.0]
[WinUI 3 - Windows App SDK 1.0.0-preview1]

Windows app type:

UWP Win32
Yes
Windows version Saw the problem?
Insider Build (22000) Yes
May 2021 Update (19043)
October 2020 Update (19042)
May 2020 Update (19041)
November 2019 Update (18363)
May 2019 Update (18362)
October 2018 Update (17763)
April 2018 Update (17134)
Fall Creators Update (16299)
Creators Update (15063)
Device form factor Saw the problem?
Desktop Yes
Xbox
Surface Hub
IoT

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-MRTThis area only covers the usage of MRT inside of a WinUI 3 appbugSomething isn't workingfix-releasedThe fix has been in a release (experimental, preview, stable, or servicing).group-languageproduct-winui3WinUI 3 issuesteam-MarkupIssue for the Markup teamv1.0.0-preview1

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions