2013-07-26 133 views
6

是 在此XAML代碼的App.xamlMergedDictionaries在XAML重寫代碼

<Application x:Class="Company.Product.App" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    > 
    <Application.Resources> 
     <ResourceDictionary> 
      <ResourceDictionary.MergedDictionaries> 
      <ResourceDictionary Source="/Company.Windows.Themes.Theme1;component/Themes/System.Windows.xaml"/> 
      <ResourceDictionary Source="/Company.Windows.Themes.Theme1;component/Themes/Company.Windows.Controls.xaml"/> 
      <ResourceDictionary Source="/Company.Windows.Themes.Theme1;component/Themes/Company.Windows.Controls.Data.xaml"/>    
      </ResourceDictionary.MergedDictionaries> 
     </ResourceDictionary> 
    </Application.Resources> 
</Application> 

等同於:

的App.xaml

<Application x:Class="Company.Product.App" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    > 
</Application> 

App.xaml.cs

public partial class App : Application 
{ 
    public App() 
    {    
     Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary() 
     { 
      Source = new Uri("/Company.Windows.Themes.Theme1;component/Themes/System.Windows.xaml", UriKind.RelativeOrAbsolute) 
     }); 
     Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary() 
     { 
      Source = new Uri("/Company.Windows.Themes.Theme1;component/Themes/Company.Windows.Controls.xaml", UriKind.RelativeOrAbsolute) 
     }); 
     Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary() 
     { 
      Source = new Uri("/Company.Windows.Themes.Theme1;component/Themes/Company.Windows.Controls.Data.xaml", UriKind.RelativeOrAbsolute) 
     }); 
    } 
} 



一個側面說明:我需要調用Application.Current.Resources.MergedDictionaries.Clear();在這種情況下,我開始添加合併字典之前?我認爲在這一刻默認 MergedDictionaries集合最初是空的。

回答

4

Ans1)絕對是。他們是一樣的。

Ans2)不,你不需要Clear()他們沒有MergedDictionaries因此Count0

+0

非常感謝你的迅速 - 幾乎立即 - 答案。 :) – kajovajo