Global static resources in a WPF class library?

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>

It was from MVVM Light;). Now, if your project is a wpf class library, what is the right way to initialize such global static resources?

+5
source share
1 answer

You can create a ResourceDictionary with your resources and combine the dictionaries using your code, as shown 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" />

the code:

 Application.Current.Resources.MergedDictionaries.Add(Application.LoadComponent(
           new Uri("/WPFProject;Component/Resources/ResourceDictionary1.xaml", UriKind.Relative)) as ResourceDictionary);
+3
source

All Articles