WPF 中使用 Resource 实现多语言

1.在解决方案项目文件夹下面找到Propertys,下边有一个Resources.resx 文件,可以在此定义界面文字。注意,要修改一下资源文件的 Custom Tool property 为PublicResXFileCodeGenerator (原为:ResXFileCodeGenerator)

2.如果要多语言,复制上边的Resource.resx .然后修改一下文件名为:Resource.zh-CN.resx

3.如果要在XAML中使用,先引用命名空间:xmlns:Property="clr-namespace:SimilarFinder.Properties",然后在页面上使用下边的方法调用:Text="{x:Static Property:Resources.ApplicationName}"

4.如果要在CS代码中调用:this.Title = SimilarFinder.Properties.Resources.ApplicationName;

5.如果要测试不同的语言环境:

CultureInfo culture = CultureInfo.CreateSpecificCulture("zh-CN");
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;

posted @ 2013-11-28 16:15  不喝啤酒的小啤酒  阅读(1501)  评论(0编辑  收藏  举报