2017-06-23 64 views
0

我們的應用程序的樣式使用ResourceDictionary。這種資源字典本身包含的資源字典這樣的:如何在WPF中只更改一個合併的資源字典?

<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合併資源字典。如何才能做到這一點?

回答

0

如果你可以在運行時設置的配置,你可以在啓動過程中做到這一點:

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

Application.Current.Resources.MergedDictionaries.Add(resourceDictionary); 
相關問題