I followed this example to build a multilingual app: How to: Build a Localized Application for Windows Phone.
I successfully bound the resource data to text like this:
<TextBlock x:Name="ApplicationTitle" Text="{Binding Path=MultiLangResources.Mainpage_Welcome, Source={StaticResource MultiLang}}"/>
And I tried to change the Thread.CurrentThread.CurrentUICulture and I can output correct key with code:
ApplicationTitle.Text = LangResource.Mainpage_Welcome;
However, the bound text never update.
How to make the bound text update like ordinary bind?
Is there anyone could help me with this problem?
I also tried this with no luck.
public class MultiLang : INotifyPropertyChanged
{
public MultiLang()
{
}
private static MLTest.LangResource multiLangResources = new GigapodV2.LangResource();
public MLTest.LangResource MultiLangResources
{
get { return multiLangResources; }
set
{
if (value != multiLangResources)
{
multiLangResources = value;
NotifyPropertyChanged("MultiLangResources");
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string property)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(property));
}
}
}
The
LangResourceclass isn’t observable by itself, and thus any bound properties from it won’t be observed. And also, the phone won’t notify all properties that’s related to the CurrentCulture just because you change it on-the-fly.Language change in that fashion would otherwise require a reboot of your app. But I would advice you to be careful with this, as the OS itself allows language swapping, meaning you need to have a really good reason for your app to allow it in itself.
The solution is to create a wrapper class, that notifies all properties that they been updated, when you change the CurrentCulture. Using Simon’s NotifyPropertyWeaver‘s [DependsOn] attribute could probably make this very easy.