2009-02-10 10 views
5

Mam następujący styl przycisków w Motywy/Generic.xaml i chcę, aby był stosowany do przycisków w całej mojej aplikacji WPF.Jak połączyć Tematy/Generic.xaml do window1.xaml?

Jak na przykład połączyć z moim window1.xaml?

<Style TargetType="{x:Type Button}"> 
    <Setter Property="SnapsToDevicePixels" Value="true"/> 
    <Setter Property="OverridesDefaultStyle" Value="true"/> 
    <Setter Property="MinHeight" Value="23"/> 
    <Setter Property="MinWidth" Value="75"/> 
    <Setter Property="Template"> 
    <Setter.Value> 
     <ControlTemplate TargetType="{x:Type Button}"> 
     <Border 
      x:Name="Border" 
      CornerRadius="2" 
      BorderThickness="1" 
      Background="#C0C0C0" 
      BorderBrush="#404040"> 
      <ContentPresenter 
      Margin="2" 
      HorizontalAlignment="Center" 
      VerticalAlignment="Center" 
      RecognizesAccessKey="True"/> 
     </Border> 
     <ControlTemplate.Triggers> 
      <Trigger Property="IsKeyboardFocused" Value="true"> 
      <Setter TargetName="Border" Property="BorderBrush" Value="#202020" /> 
      </Trigger> 
      <Trigger Property="IsDefaulted" Value="true"> 
      <Setter TargetName="Border" Property="BorderBrush" Value="#202020" /> 
      </Trigger> 
      <Trigger Property="IsMouseOver" Value="true"> 
      <Setter TargetName="Border" Property="Background" Value="#808080" /> 
      </Trigger> 
      <Trigger Property="IsPressed" Value="true"> 
      <Setter TargetName="Border" Property="Background" Value="#E0E0E0" /> 
      <Setter TargetName="Border" Property="BorderBrush" Value="#606060" /> 
      </Trigger> 
      <Trigger Property="IsEnabled" Value="false"> 
      <Setter TargetName="Border" Property="Background" Value="#EEEEEE" /> 
      <Setter TargetName="Border" Property="BorderBrush" Value="#AAAAAA" /> 
      <Setter Property="Foreground" Value="#888888"/> 
      </Trigger> 
     </ControlTemplate.Triggers> 
     </ControlTemplate> 
    </Setter.Value> 
    </Setter> 
</Style> 
+2

Wiem, że to pytanie jest stary, ale ... Sugerowałbym, że jeśli chcesz zmienić domyślny styl przycisku ..., przenieś powyższy plik xaml do pliku App.xaml. Generic.xaml ma określony cel jako mechanizm awaryjny dla stylu kompozycji WPF. Zobacz link (według utworu) poniżej do innego postu StackOverflow z dodatkowymi informacjami na ten temat. – cplotts

+1

Heck, odpowiedź Muad'Diba poniżej ... niejasno sugeruje to, co mówię ... poprzez połączenie DefaultStyles.xaml w ... zamiast Generic.xaml. :-) – cplotts

Odpowiedz

8

w Widow1.xaml (lub App.xaml, zmienia się) ......

<Window1.Resources> 
    <ResourceDictionary> 
     <ResourceDictionary.MergedDictionaries> 
      <ResourceDictionary Source="DefaultStyles.xaml"/> 
     </ResourceDictionary.MergedDictionaries> 
    </ResourceDictionary> 
</Window1.Resources> 
+0

To wszystko, dziękuję! –

Powiązane problemy