为了使我的wpf appliaction本地化,我遵循了这个CodeProject教程.
我创建了我的本地化资源文件(例如,Resource.resx,Resource.en-US.resx)并将它们绑定在xaml中的label元素上
<Label Foreground="{StaticResource ApplicationForgroundColor}" FontSize="21"
Content="{x:Static strings:Resources.title}"/>
Run Code Online (Sandbox Code Playgroud)
在LocalizedService中,我设置了CultureInfo一些更改事件
class LocalizationService
{
public static void SetLanguage(string locale)
{
if (string.IsNullOrEmpty(locale)) locale = "en-US";
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(locale);
}
}
Run Code Online (Sandbox Code Playgroud)
此解决方案编译并显示正确的资源值,但由于静态绑定,我无法在运行时更改语言环境.当我将内容绑定更改DynamicResource为如下所示时,没有显示资源值.
Content="{DynamicResource strings:Resources.title}"
Run Code Online (Sandbox Code Playgroud)
如何将文本值绑定到本地化资源文件并在运行时动态更改?