Reputation: 55
I am trying to change a language at a UWP app so that the my x:uid objects related and my ResourceLoader based objects would change. I am using, as recommended at other Q&A :
ApplicationLanguages.PrimaryLanguageOverride = newLanguage;
Windows.ApplicationModel.Resources.Core.ResourceContext.GetForCurrentView().Reset();
Windows.ApplicationModel.Resources.Core.ResourceContext.GetForViewIndependentUse().Reset();
Frame.Navigate(this.GetType());
However, everything that is controlled directly by the ResourceLoader is changed and whatever is created at the xaml with x:uid don't. If I change the language again then, x:uid changes to the previous language and the rest is at the new selected language.
I think that there might be something that is related to thread behavior for two reasons. First, a suggestion to fix it, that works, is to delay the thread before the navigation. Second, I have different behavior at virtual and physical machines (this bug happens at the physical machine obviously).
I would really appreciate a solution or an explanation that allows good functionality that is not based on delaying threads.
Some other related Q&As:
UWP MVVM: refresh page after change of language
C# change app language programmatically UWP realtime
Thanks
Upvotes: 4
Views: 513
Reputation: 32775
I have reported this issue, and currently there is a workaround that use delay after Reset
method invoked. You could refer the following code.
using System.Threading.Tasks;
static bool m_bFirstLanguageChangeNavigation = true;
async private void Show_Click(object sender, RoutedEventArgs e)
{
var context = ResourceContext.GetForCurrentView();
var selectedLanguage = MyComboBox.SelectedValue;
var lang = new List<string>();
lang.Add(selectedLanguage.ToString());
ApplicationLanguages.PrimaryLanguageOverride = selectedLanguage.ToString();
ResourceContext.GetForCurrentView().Reset();
ResourceContext.GetForViewIndependentUse().Reset();
//added to work the first time
if (m_bFirstLanguageChangeNavigation)
{
m_bFirstLanguageChangeNavigation = false;
await Task.Delay(100);
}
Frame.Navigate(this.GetType());
}
Upvotes: 3