Search code examples
c#wpfresx

Use RESX file in WPF application with Prism


I'm working on a project with WPF/Prism. The application has different modules and one of those modules can change the culture of the resx object. This works fine and each module loaded will display the translated text.

In case any module has already been loaded, the text will not be updated. First, I tried an approach with x:Static but quickly realized that a static value doesn't help my issue. Now I've implemented a get-only property in my view model that returns the localized string.

public string UserDetailsLabel => Messages.UserDetailsLabel;

<TextBlock Text="{Binding UserDetailsLabel, Mode=OneWay, NotifyOnSourceUpdated=True}"/>

However, I have no idea where to tell WPF (or Prism) that the culture has changed and to update the displayed value. The module that changes the culture sets the Culture property on Messages (generated in Messages.Designer.cs).

Is there a way to notify that the value changed?


Solution

  • Is there a way to notify that the value changed?

    Implement INotifyPropertyChanged and raise the PropertyChanged event for the data-bound UserDetailsLabel property.

    This is the way to notify WPF that the source value has changed.

    In the context of a multi-module Prism application, you could for example use the event aggregator to raise an event that each view model handles by raising the PropertyChanged event for all data-bound properties that need to be refreshed in the view.