XAML Binding in binding

泪湿孤枕 提交于 2019-12-10 12:05:24

问题


I'd like to bind "MenuItemDescription" How?

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

Sorry for my English, I use google translate to help me


回答1:


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.

For the first case you need to bind to a static property, e.g.:

<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). 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, e.g.:

In your dictionary

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

In your control

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


来源:https://stackoverflow.com/questions/9257888/xaml-binding-in-binding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!