WPF类库中的全局静态资源? [英] Global static resources in a WPF class library?
本文介绍了WPF类库中的全局静态资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在WPF应用程序中,您可以将全局静态资源放入app.xaml ..之类的
In a WPF application, you can put your global static resources in app.xaml .. like
<Application.Resources>
<!--Global View Model Locator-->
<vm:ViewModelLocator x:Key="Locator"
d:IsDataSource="True" />
</Application.Resources>
那是来自MVVM Light;).现在,如果您的项目是wpf类库,那么初始化此类全局静态资源的正确方法是什么?
That was from MVVM Light ;). Now, if your project is a wpf class library, what is a proper way to initialize such global static resources?
推荐答案
您可以使用资源创建ResourceDictionary,并使用下面的代码合并字典.
You can create a ResourceDictionary with your resources and merge the dictionaries using your code as below.
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:vm="clr-namespace:WPFProject.ViewModel"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<vm:ViewModelLocator x:Key="Locator"
d:IsDataSource="True" />
代码:
Application.Current.Resources.MergedDictionaries.Add(Application.LoadComponent(
new Uri("/WPFProject;Component/Resources/ResourceDictionary1.xaml", UriKind.Relative)) as ResourceDictionary);
这篇关于WPF类库中的全局静态资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文