2011-06-03 148 views
3

我有一個我正在開發的WPF應用程序,它允許用戶切換當前主題。我想出如何switch themes ...但現在看來,該應用程序的背景不受主題:WPF主題不適用於背景

enter image description here

(我混合三張照片一起,以節省空間)

如何我能解決這個問題嗎?它清楚地表明here的背景應該改變...

下面是我使用的代碼:

MainWindow.xaml

<Window x:Class="GDE.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Title="MainWindow" Height="350" Width="525" MinWidth="525" MinHeight="350"> 
    <Grid> 
     .... 
    </Grid> 
</Window> 

App.xaml

<Application x:Class="GDE.App" 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      StartupUri="MainWindow.xaml"> 
    <Application.Resources> 
     <ResourceDictionary> 
      <ResourceDictionary.MergedDictionaries> 
       <ResourceDictionary x:Name="ThemeDictionary"> 
        <ResourceDictionary.MergedDictionaries> 
         <ResourceDictionary Source="/Themes/ExpressionDark.xaml"/> 
        </ResourceDictionary.MergedDictionaries> 
       </ResourceDictionary> 
      </ResourceDictionary.MergedDictionaries> 
     </ResourceDictionary> 
    </Application.Resources> 
</Application> 
+0

你可以發佈一些代碼,以便我們可以看到你在做什麼? – evanb 2011-06-03 17:11:21

+0

用代碼 – Entity 2011-06-03 18:12:08

回答

6

的主題定義背景,但你需要設置它自己,因爲它沒有被任何地方引用的主題中:

Background="{DynamicResource WindowBackgroundBrush}" 

爲什麼?我假設,因爲樣式不會自動應用到派生類,所以如果設置了樣式並且需要明確設置,因爲通常使用Window的子類,例如, MainWindow

0

我的猜測是因爲我們在屏幕截圖中看到的背景不屬於主題之一,而這就是問題所在,你會重寫主題當手動設置的東西。

+0

更新好*我*無法在任何地方設置背景顏色... – Entity 2011-06-03 18:09:13