1
votes

I've started using the WPF Localization Extension to localize my resources for WPF projects. I like the library because it can easily locate resource's out of the XAML-Code.

When I want to use the library to localize my resources in C# I have some problems. For a MessageBar (designed as UserControl in WPF) I want to set the displayed message in C# Code (ViewModel). The localized strings are stored in resource-files (the same which I used to localize strings in XAML).

Now my question, how can I localize my resources in C#-Code using the WPF Localization Extension? What is the best practice?

1

1 Answers

0
votes

You can access your string values using this code.

public static string GetUIString(string key)
{
      string uiString;
      LocTextExtension locExtension = new LocTextExtension(key);
      locExtension.ResolveLocalizedValue(out uiString);
      return uiString;
}

Declare this method at a place where it is accessible to all the other classes. Then call it where ever you need the resource string and pass the resource key