[英]XAML Binding in binding
I'd like to bind "MenuItemDescription" How? 我想绑定“MenuItemDescription”如何?
Text="{Binding Path=LocalizedRessources.MenuItemDescription, Source={StaticResource LocalizedStrings}}"
In advance thank you 提前谢谢你
edit: 编辑:
I'll try to be more explicit: I'd like to replace "MenuItemDescription" which is currently hard coded by a string dynamicly using a binding 我将尝试更明确:我想替换当前使用绑定动态地通过字符串硬编码的“MenuItemDescription”
Sorry for my English, I use google translate to help me 抱歉我的英文,我使用谷歌翻译来帮助我
I'm guessing you either want to bind to a string defined in a Windows resource file (.resx), or you want to use a value defined in a WPF resource dictionary. 我猜你要么绑定到Windows资源文件(.resx)中定义的字符串,要么想要使用WPF资源字典中定义的值。
For the first case you need to bind to a static property, eg: 对于第一种情况,您需要绑定到静态属性,例如:
<TextBlock Text="{Binding Source={x:Static
MyApplication:LocalizedResource.MenuItemDescription}}"/>
Since you can only bind to public static properties you need to change the access modifier of your LocalizedResources.resx to public (defaults to internal). 由于您只能绑定到公共静态属性,因此需要将LocalizedResources.resx的访问修饰符更改为public(默认为internal)。 Open the resource file and you can change the access modifier.
打开资源文件,您可以更改访问修饰符。
For the second case you need to define the string in a resource dictionary (possibly app.xaml) and then use that as a static resource, eg: 对于第二种情况,您需要在资源字典(可能是app.xaml)中定义字符串,然后将其用作静态资源,例如:
In your dictionary 在你的字典里
<System:String x:Key="MenuItemDescription">My menu item</System:String>
In your control 在你的控制中
<TextBlock Text="{StaticResource MenuItemDescription}"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.