如何在WPF中只更改一个合并的资源字典?

时间:2017-06-23 16:39:04

标签: wpf styles resourcedictionary

我们的应用程序使用ResourceDictionary作为其样式。此资源字典本身包含资源字典:

<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>

所以,现在,根据构建配置,我们只想更改Brushes.xaml合并资源字典。怎么办呢?

1 个答案:

答案 0 :(得分:0)

如果您可以在运行时设置配置,则可以在启动期间执行此操作:

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

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