WPF, localisation: reevaluating control values

310 views Asked by At

I'm doing a small research on localisation methods in WPF. I heard about the idea with markup extension:

<Label Content="{local:Translate {-- label ID here --}}" />

I like this solution very much: it's extremely easy to implement and seems to be nicely flexible. I've got one concern, however. Let's suppose, that user changes the locale in the runtime. How to ensure, that localized properties will be reevaluated to match new language?

1

There are 1 answers

3
Aaron McIver On BEST ANSWER

You would need to call DependencyObject.InvalidateProperty. Keep in mind that if you were binding to an object implementing INotifyPropertyChanged they would reevaluate by way of the underlying data changing.

DependencyObject.InvalidateProperty can be called on a given DependencyProperty such as Label.Content.

Label label = new Label();
label.InvalidateProperty(ContentProperty);

This would have to be done for the varying properties that need re-evaluation. There is an in depth article on MSDN around localization within WPF for varying alternatives as well that should be investigated.