How to update culture on CoreApplicationView when I changing culture in main window?

bexolder 21 Reputation points
2021-08-03T13:17:21.227+00:00

I have multiple views app, and I want update culture in runtime (using setting page). For main window I do this:

ApplicationLanguages.PrimaryLanguageOverride = currentCulture.Name;
Windows.ApplicationModel.Resources.Core.ResourceContext.ResetGlobalQualifierValues();
var currentFrame = Window.Current.Content as Frame;
currentFrame.Navigate(currentFrame.Content.GetType());
Globals.Navigation.OnCanNavigate(new NavigateEventArgs { TargetPageTag = NavigationItem.Home });

Its work correctly, but my CoreApplicatioViews dont change culture. I cant do the same for CoreApplicationView, because I dont have his frame for navigation.

Universal Windows Platform (UWP)
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,390 questions
0 comments No comments
{count} votes

Accepted answer
  1. Nico Zhu (Shanghai Wicresoft Co,.Ltd.) 12,856 Reputation points
    2021-08-04T06:56:23.933+00:00

    Hello, Welcome to Micorosoft Q&A,

    but my CoreApplicatioViews dont change culture. I cant do the same for CoreApplicationView, because I dont have his frame for navigation.

    If you want to refresh the secondary ApplicationView from your main window. the better way is using Messenger send refresh command to secondary, and refresh secondary internal

    For example

    MainView

    private void AlterButton_Click(object sender, RoutedEventArgs e)  
    {     
        Messenger.Default.Send<bool,OtherPage>(true);  
         
    }  
    

    Secondary

    protected override void OnNavigatedTo(NavigationEventArgs e)  
    {  
        base.OnNavigatedTo(e);  
        Messenger.Default.Register<bool>(this, async (s) =>  
        {  
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>  
            {  
                Reload();  
            });  
      
        });  
    }  
      
    public bool Reload() { return Reload(null); }  
    private bool Reload(object param)  
    {  
        Type type = this.Frame.CurrentSourcePageType;  
        if (this.Frame.BackStack.Any())  
        {  
            type = this.Frame.BackStack.Last().SourcePageType;  
            param = this.Frame.BackStack.Last().Parameter;  
        }  
        try { return this.Frame.Navigate(type, param); }  
        finally { this.Frame.BackStack.Remove(this.Frame.BackStack.Last()); }  
    }  
    

    For using Messenger you could refer mvvmlight Messenger document.


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful