XAML绑定绑定

时间:2012-02-13 09:09:52

标签: windows silverlight windows-phone-7 xaml windows-phone-7.1

我想绑定“MenuItemDescription” 怎么样?

Text="{Binding Path=LocalizedRessources.MenuItemDescription, Source={StaticResource LocalizedStrings}}"

提前谢谢

编辑:

我会尝试更明确: 我想替换“MenuItemDescription”,它目前使用绑定动态地通过字符串进行硬编码

对不起我的英文,我使用谷歌翻译来帮助我

1 个答案:

答案 0 :(得分:2)

我猜你要么绑定到Windows资源文件(.resx)中定义的字符串,要么想要使用WPF资源字典中定义的值。

对于第一种情况,您需要绑定到静态属性,例如:

<TextBlock Text="{Binding Source={x:Static
MyApplication:LocalizedResource.MenuItemDescription}}"/>

由于您只能绑定到公共静态属性,因此需要将LocalizedResources.resx的访问修饰符更改为public(默认为internal)。打开资源文件,您可以更改访问修饰符。

对于第二种情况,您需要在资源字典中定义字符串(可能是app.xaml),然后将其用作静态资源,例如:

在你的词典中

<System:String x:Key="MenuItemDescription">My menu item</System:String>

在你的控制中

<TextBlock Text="{StaticResource MenuItemDescription}"/>