2012-02-15 21 views
0

我有表達式黑暗主題整個 WPF應用程序。如何禁止用戶控件的WPF全局應用程序主題?

<Application x:Uid="Application_1" x:Class="MyShow.Player.App" 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      StartupUri="MainWindow.xaml" 
      SessionEnding="App_SessionEnding" > 
    <Application.Resources> 
     <ResourceDictionary x:Uid="ResourceDictionary_1" > 
      <ResourceDictionary.MergedDictionaries> 
       <ResourceDictionary x:Uid="ResourceDictionary_3" Source="/Themes/ExpressionDark.xaml" /> 
      </ResourceDictionary.MergedDictionaries> 
     </ResourceDictionary> 
    </Application.Resources> 
</Application> 

我所擁有的是這個Expression Dark適用於所有用戶控件(public partial class UControl : UserControl)。

我想要的是使用完全不同的主題,如Aero或其他所有WPF用戶控件。

我該怎麼做?

謝謝!

+0

定義「WPF用戶控件」 – 2012-02-15 17:34:00

+0

@jberger它是公共分部類UControl:UserControl – 2012-02-15 17:43:48

回答

2

創建啓動事件並在啓動事件處理程序中設置主題。該主題將應用於該解決方案中的所有用戶控制。在你的情況。

//App.xaml 

<Application x:Uid="Application_1" x:Class="MyShow.Player.App" 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      StartupUri="MainWindow.xaml" 
      SessionEnding="App_SessionEnding" 
      Startup="Application_Startup"> 

//App.xaml.cs 

private void Application_Startup(object sender, StartupEventArgs e) 
     { 
      StyleManager.ApplicationTheme = new MetroTheme(); //Set your theme   
     }