2009-02-10 8 views
5

Ho il seguente stile di pulsante in Temi/Generic.xaml e voglio che si applichi ai pulsanti ovunque nella mia applicazione WPF.Come connettere Themes/Generic.xaml a window1.xaml?

Come collegarlo a window1.xaml, ad esempio?

<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

So che questa è una vecchia questione ... ma Suggerirei che se si desidera semplicemente modificare lo stile Button predefinito ... si sposta il file xaml sopra nel file App.xaml. Generic.xaml ha uno scopo specifico di essere un meccanismo di fallback per lo stile dei temi di WPF. Vedi il link (per canzone) qui sotto ad un altro post StackOverflow con maggiori informazioni su questo argomento. – cplotts

+1

Heck, la risposta di Muad'Dib sotto ... suggerisce implicitamente quello che sto dicendo ... unendo DefaultStyles.xaml in ... invece di Generic.xaml. :-) – cplotts

risposta

8

nel vostro Widow1.xaml (o il vostro App.xaml, cambiando a) ......

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

Ecco, grazie! –