Dabblernl
Dabblernl

Reputation: 16141

How to change just one merged resource dictionary in WPF?

Our application uses a ResourceDictionary for its styles. This resource dictionary itself contains resource dictionaries thus:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="BridgeIt5/General.xaml" />
    <ResourceDictionary Source="BridgeIt5/Brushes.xaml" />
    <ResourceDictionary Source="BridgeIt5/Constants.xaml" />
    <ResourceDictionary Source="BridgeIt5/Button.xaml" />
     ...
</ResourceDictionary.MergedDictionaries>

So, now depending on the build configuration we just want to change the Brushes.xaml merged resource dictionary. How can this be done?

Upvotes: 0

Views: 605

Answers (1)

Lockdowne
Lockdowne

Reputation: 484

If you can set the configuration at runtime you can do this during startup:

var resourceDictionary = new ResourceDictionary
{
    // Pick uri from configuration
    Source = new Uri("BridgeIt5/Brushes.xaml"),
};

Application.Current.Resources.MergedDictionaries.Add(resourceDictionary);

Upvotes: 1

Related Questions