I have a static class in which one property defines a resource manager. for eg.开发者_如何学C
public static class MyClass
{
public static MyResourceManager {get;set;}
}
I want to bind the key from the resource manager to XAML. I am using Silverlight 4 with MVVM pattern.
If I do something like this:
<Button Content="{Binding LocalResource.Refresh}"/>
where LocalResource is defined in my view model like this:
public object LocalResource {
get
{
return MyClass.MyResourceManager;
}
}
Can anyone suggest a better approach. I have made the class static as the resource file is loaded dynamically. I am loading it in the bootsrapper and have to use this across all my modules.
How about instanciating your resourcemanager just once for your application like this:
<Application xmlns:myNS="clr-namespace:MyNamespace;assembly=MyAssembly" ...>
<Application.Resources>
<myNS:MyResourceManager x:Key="MyResources" />
</Application.Resources>
</Application>
Then you can use it just like a normal WPF resource:
<Button Content="{Binding Source={StaticResource MyResources}, Path=Refresh}" />
精彩评论