title: Bind Button Template Foreground to property of class which derives from Button
body: <p>I'd like to set individual highlighting colors for my buttons so I created a new class "HighlightButton" which derives from Button and exposes only one additional Property (DP Property) - SolidColorBrush HighlightColor.</p>
  
  <pre><code>public class HighlightButton : Button {
      public SolidColorBrush HighlightColor {
          get { return (SolidColorBrush)GetValue(HighlightColorProperty); }
          set { SetValue(HighlightColorProperty, value); }
      }
  
      // Using a DependencyProperty as the backing store for HighlightColor.  This enables animation, styling, binding, etc...
      public static readonly DependencyProperty HighlightColorProperty =
          DependencyProperty.Register("HighlightColor", typeof(SolidColorBrush), typeof(HighlightButton), new PropertyMetadata(new SolidColorBrush(System.Windows.Media.Color.FromRgb(255,255,255))));
  }
  </code></pre>
  
  <p>-</p>
  
  <p>Now I use this HighlightButton instead of Button inside my XAML:</p>
  
  <pre><code>&lt;con:HighlightButton Style="{StaticResource TransparentButton}"
              x:Name="_backButton"
              CommandParameter="{Binding PreviousPageViewModel}" 
              Command="{Binding DataContext.ChangePageCommand, RelativeSource={RelativeSource AncestorType=Window}}"
              HighlightColor="Yellow"/&gt;
  </code></pre>
  
  <p>-</p>
  
  <p>The TransparentButton Style is defined inside a Resource Dictionary:</p>
  
  <pre><code>&lt;Style TargetType="con:HighlightButton" x:Name="_transparentButton" x:Key="TransparentButton"&gt;
      &lt;Setter Property="Height" Value="50"/&gt;
      &lt;Setter Property="Width" Value="50"/&gt;
      &lt;Setter Property="Foreground" Value="White"/&gt;
      &lt;Setter Property="Template"&gt;
          &lt;Setter.Value&gt;
              &lt;ControlTemplate TargetType="Button"&gt;
                  &lt;Border Background="Transparent"&gt;
                      &lt;ContentPresenter HorizontalAlignment="Center" 
                                        VerticalAlignment="Center"/&gt;
                  &lt;/Border&gt;
                  &lt;ControlTemplate.Triggers&gt;
                      &lt;Trigger Property="IsMouseOver" Value="True"&gt;
                          &lt;Setter Property="Foreground" Value="{Binding HighlightColor}"/&gt;
                      &lt;/Trigger&gt;
                      &lt;Trigger Property="IsEnabled" Value="False"&gt;
                          &lt;Setter Property="Foreground" Value="Gray"/&gt;
                      &lt;/Trigger&gt;
                  &lt;/ControlTemplate.Triggers&gt;
              &lt;/ControlTemplate&gt;
          &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
  &lt;/Style&gt;
  </code></pre>
  
  <p>As you can see I'd like my buttons to swich to a individually set foreground color when hovering over it. Unfortunately (as you may expect) this solution does not work. WPF is looking inside my ViewModel for the Property HightlightColor (TargetType="Button" does not know anything about HighlightColor). Sadly when I change the TargetType to my HighlightButton the whole Style crashes. </p>
  
  <p>Is it even possible to achive what I'm looking for? What am I doing wrong?</p>