问题
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