Jans的BLOG
Jans的BLOG

WPF用Resource.resX中的字符串进行国际化

增加命名空间

xmlns:prop="clr-namespace:XXAppName.Properties"

引用的地方的格式如下:

<Button x:Uid="testButtonId" Content="{x:Static prop:Resources.Please}" />

在ResX文件中有一个词条叫Please,

在设计器中可以看到,按钮的文字已经变成对应的词条了,但是运行时会发生

Provide value on 'System.Windows.Markup.StaticExtension' threw an exception.'

放狗搜到微软的方法:

I believe your resources are generated as an internal class. WPF is trying to resolve resource from another assembly so it wont succeed until your resources are marked as public. Consider using PublicResXFileCodeGenerator tool introduced in Visual Studio 2008.

在Solution Exploer里选中Resources.resX 在下面的自定义工具里把

ResXFileCodeGenerator改为

PublicResXFileCodeGenerator

选中Resources.resX 点运行自定义工具

重新编译,运行,问题解决。

posted on 2013-09-17 15:55  Jans  阅读(438)  评论(0编辑  收藏  举报