<Window x:Class="ControlTemplates.ButtonTemplate"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="ControlTemplates" Height="300" Width="300"
    >
  <Window.Resources>
    <LinearGradientBrush x:Key="NormalBrush" StartPoint="0,0" EndPoint="0,1">
      <GradientBrush.GradientStops>
        <GradientStopCollection>
          <GradientStop Color="#FFF" Offset="0.0"/>
          <GradientStop Color="#CCC" Offset="1.0"/>
        </GradientStopCollection>
      </GradientBrush.GradientStops>
    </LinearGradientBrush>

    <LinearGradientBrush x:Key="DefaultedBorderBrush" StartPoint="0,0" EndPoint="0,1">
      <GradientBrush.GradientStops>
        <GradientStopCollection>
          <GradientStop Color="#777" Offset="0.0"/>
          <GradientStop Color="#000" Offset="1.0"/>
        </GradientStopCollection>
      </GradientBrush.GradientStops>
    </LinearGradientBrush>

    <LinearGradientBrush x:Key="DarkBrush" StartPoint="0,0" EndPoint="0,1">
      <GradientBrush.GradientStops>
        <GradientStopCollection>
          <GradientStop Color="#FFF" Offset="0.0"/>
          <GradientStop Color="#AAA" Offset="1.0"/>
        </GradientStopCollection>
      </GradientBrush.GradientStops>
    </LinearGradientBrush>

    <LinearGradientBrush x:Key="PressedBrush" StartPoint="0,0" EndPoint="0,1">
      <GradientBrush.GradientStops>
        <GradientStopCollection>
          <GradientStop Color="#BBB" Offset="0.0"/>
          <GradientStop Color="#EEE" Offset="0.1"/>
          <GradientStop Color="#EEE" Offset="0.9"/>
          <GradientStop Color="#FFF" Offset="1.0"/>
        </GradientStopCollection>
      </GradientBrush.GradientStops>
    </LinearGradientBrush>

    <LinearGradientBrush x:Key="PressedBorderBrush" StartPoint="0,0" EndPoint="0,1">
      <GradientBrush.GradientStops>
        <GradientStopCollection>
          <GradientStop Color="#444" Offset="0.0"/>
          <GradientStop Color="#888" Offset="1.0"/>
        </GradientStopCollection>
      </GradientBrush.GradientStops>
    </LinearGradientBrush>

    <SolidColorBrush x:Key="DisabledBackgroundBrush" Color="#EEE" />
    <SolidColorBrush x:Key="DisabledBorderBrush" Color="#AAA" />
    <SolidColorBrush x:Key="DisabledForegroundBrush" Color="#888" />
    <LinearGradientBrush x:Key="NormalBorderBrush" StartPoint="0,0" EndPoint="0,1">
      <GradientBrush.GradientStops>
        <GradientStopCollection>
          <GradientStop Color="#CCC" Offset="0.0"/>
          <GradientStop Color="#444" Offset="1.0"/>
        </GradientStopCollection>
      </GradientBrush.GradientStops>
    </LinearGradientBrush>
    
    <ControlTemplate x:Key="ButtonTemplate" TargetType="{x:Type Button}">
      <Border 
        x:Name="Border"  
        CornerRadius="2" 
        BorderThickness="1"
        Background="{StaticResource NormalBrush}"
        BorderBrush="{StaticResource NormalBorderBrush}">
        <ContentPresenter 
          Margin="{TemplateBinding Button.Padding}"
          HorizontalAlignment="Center"
          VerticalAlignment="Center"
          RecognizesAccessKey="True"/>
      </Border>
      <ControlTemplate.Triggers>
        <Trigger Property="IsKeyboardFocused" Value="True">
          <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource DefaultedBorderBrush}" />
        </Trigger>
        <Trigger Property="IsDefaulted" Value="true">
          <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource DefaultedBorderBrush}" />
        </Trigger>
        <Trigger Property="IsMouseOver" Value="true">
          <Setter TargetName="Border" Property="Background" Value="{StaticResource DarkBrush}" />
        </Trigger>
        <Trigger Property="IsPressed" Value="true">
          <Setter TargetName="Border" Property="Background" Value="{StaticResource PressedBrush}" />
          <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource PressedBorderBrush}" />
        </Trigger>
        <Trigger Property="IsEnabled" Value="false">
          <Setter TargetName="Border" Property="Background" Value="{StaticResource DisabledBackgroundBrush}" />
          <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource DisabledBorderBrush}" />
          <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
        </Trigger>
      </ControlTemplate.Triggers>
    </ControlTemplate>   
    
  </Window.Resources>
  
  
    <StackPanel Margin="5">
      <Button Padding="5" Margin="3">Normal Button</Button>
      <Button Padding="5" Margin="3" Template="{StaticResource ButtonTemplate}">Templated Button</Button>
    </StackPanel>
</Window>
