在 WPF 应用程序中,您可以将全局静态资源放入 app.xaml 中...就像
<Application.Resources>
<!--Global View Model Locator-->
<vm:ViewModelLocator x:Key="Locator"
d:IsDataSource="True" />
</Application.Resources>
那是来自 MVVM Light ;)。现在,如果您的项目是 wpf 类库,那么初始化此类全局静态资源的正确方法是什么?
您可以使用您的资源创建一个 ResourceDictionary,并使用您的代码合并字典,如下所示。
<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" />
Code:
Application.Current.Resources.MergedDictionaries.Add(Application.LoadComponent(
new Uri("/WPFProject;Component/Resources/ResourceDictionary1.xaml", UriKind.Relative)) as ResourceDictionary);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)