Question

I have the following problem. My WPF solution include two resx files with only two rows

Resources.resx -Name: IsManager Value: Yes | Name: IsNotManager Value: No
Resources.pl-PL.resx -Name: IsManager Value : Tak | Name: IsNotManager Value: Nie

I also have simple textblock in MainWindow

<TextBlock Text="{x:Static prop:Resources.IsManager}" />

Question is why when I change CurrentUICulture to pl-PL, the text property in TextBlock doesn't change ? I understand that property is initialized only once and I should 'refresh' the value of this property, but is there any option to do this automaticly ? Below code where I change it.

private void Button_Click_1(object sender, RoutedEventArgs e)
{
    Thread.CurrentThread.CurrentUICulture = new CultureInfo("pl-PL");
}

What can I do to change this Text property ?

Was it helpful?

Solution

If you bind to a static value it will not refresh, you must open the window or recreate the view or what is your UI, more precise the textblock must be recreated in order to evaluate the Text property once again.

The solution is runtime localization. You have several alternatives.

  1. Using Dynamic Resources and bindings: http://www.codeproject.com/Articles/17334/Localizing-WPF-Applications-using-Locbaml

  2. Using an ObjectdataProvider: http://www.codeproject.com/Articles/22967/WPF-Runtime-Localization#AutomaticUpdatingWithODP

You can find several good resources by searching after WPF runtime localization like http://altfo.wordpress.com/2009/02/18/wpf-localization-or-xaml-localization/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top