2014-03-06 57 views
0
app.xaml 

<Application.Resources> 
    <local:AppBootstrapper xmlns:local="clr-namespace:Kyms" x:Key="Bootstrapper" /> 
    <local:LocalizedStrings xmlns:local="clr-namespace:Kyms" x:Key="LocalizedStrings"/> 
    <ResourceDictionary x:Key="CustomDictionary"> 
     <ResourceDictionary.MergedDictionaries> 
      <ResourceDictionary Source="Styles/Styles.xaml" /> 
     </ResourceDictionary.MergedDictionaries> 
    </ResourceDictionary> 
</Application.Resources> 

我的資源在樣式/ Styles.xaml的ResourceDictionary與卡利微

<ResourceDictionary 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"> 


<Style x:Key="MyColorButton" TargetType="Button"> 
    ....... 
</Style> 

在視圖模型(使用卡利微MVVM模式),如果我把這個代碼

應用。 Current.Resources.MergedDictionaries [0]

App.Current.Resources.MergedDictionaries.Count = 0

但不是它的工作原理,爲什麼呢?

回答

0

我解決了我的AppBootstrapper.cs

我是插入

private void LoadDictionary() 
    { 
     var dictionaries = App.Current.Resources.MergedDictionaries; 
     dictionaries.Clear(); 

     var themeStyles = new ResourceDictionary { Source = new Uri("/MyAssemblyName;component/Styles/Styles.xaml", UriKind.RelativeOrAbsolute) }; 
     dictionaries.Add(themeStyles); 
    } 

和它的作品!