5

I have the following button style in Themes/Generic.xaml and I want it to apply to buttons everywhere in my WPF application.

How do I connect it to my window1.xaml for instance?

<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>
Edward Tanguay
  • 189,012
  • 314
  • 712
  • 1,047
  • 2
    I know this is an old question ... but I would suggest that if you just want to change the default Button style ... that you move the above xaml into your App.xaml file. Generic.xaml has a specific purpose of being a fallback mechanism for WPF's theme styling. See the link (by song) below to another StackOverflow post with more info on this subject. – cplotts Jan 14 '11 at 21:02
  • 1
    Heck, Muad'Dib's answer below ... sort of implicitly suggests what I'm saying ... by merging DefaultStyles.xaml in ... instead of Generic.xaml. :-) – cplotts Jan 14 '11 at 21:06

1 Answers1

8

in your Widow1.xaml (or your App.xaml, changing to ) ......

<Window1.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="DefaultStyles.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Window1.Resources>
Muad'Dib
  • 28,542
  • 5
  • 55
  • 68