views:

74

answers:

1

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>

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?

+1  A: 

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"&gt;
<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);
Ragunathan