I have a WPF window and many labels are using localized strings. For example :
<Window x:Class="CoHOLauncher.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="clr-namespace:System;assembly=mscorlib"
xmlns:l="clr-namespace:MyNameSpace"
xmlns:loc="clr-namespace:MyNameSpace.Localization">
<Label Grid.Column="0" Content="{x:Static loc:Strings.MainWindowSize}" HorizontalAlignment="Right"/>
Details of the Strings class as follow :
public class Strings {
private static global::System.Globalization.CultureInfo resourceCulture;
public static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MyNameSpace.Localization.Strings", typeof(Strings).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
public static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
public static string MainWindowSize {
get {
return ResourceManager.GetString("MainWindowSize", resourceCulture);
}
}
}
If I changed Strings.Culture in run time, how to force WPF to reload all strings ?
I store all strings in a localization satellite DLL assemblies , which are generated from localized resource files .
You would have to change the binding source from an
x:Staticvalue and somehow expose the localized strings through a property that provides value change notifications.