2012-10-31 51 views
3

我在網格中的以下資源XML:WPF選項經典主題

<Grid.Resources> 
    <ResourceDictionary> 
     <ResourceDictionary.MergedDictionaries> 
      <ResourceDictionary Source="/PresentationFramework.Classic;component/themes/classic.xaml" /> 
     </ResourceDictionary.MergedDictionaries> 
    </ResourceDictionary> 
</Grid.Resources> 

而且這個工作,我在經典主題加載。但經典的主題按鈕背景很白?有什麼方法可以更改此主題中按鈕的默認背景顏色?

回答

1

您可以使用樣式來僅將背景色設置爲不同的東西。

<Style TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}"> 
     <Setter Property="Background" Value="Green" /> 
</Style> 

我通常都在那裏我存儲我所有的自定義主題數據的XAML文件並加載它

<ResourceDictionary Source="Themes\MyTheme.xaml"/> 

在這種情況下,將包含以下

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

    <Style TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}"> 
     <Setter Property="Background" Value="Green" /> 
    </Style> 

</ResourceDictionary> 

這裏的關鍵是使用BasedOn="{StaticResource {x:Type Button}}",因爲這將確保我們將按鈕設置爲當前的style/theme。在這種情況下,這將是Classic。如果我們不指定任何值,它將僅僅基於原始主題,即Aero

+0

如果我添加這個,並將鼠標懸停在按鈕上。按鈕主題轉向Aero? – ProgrammerAtWork

+0

對不起,我更新了代碼。 – eandersson