title: WPF add custom attribute for control style in ResourceDictionary
body: <p>I am making a skin for WPF and store all the styles in ResourceDictionary. I wrote a button template which has many various colors, eg: <code>PrimaryHover</code>, <code>PrimaryActive</code> etc. If I want to add a new style with other colors, I'll need to copy and paste this code and replace colors in whole code. So as not to do this, I want to create custom properties which will contain colors and point them in the triggers. I created a class with properties but it's invisible inside the ResourceDictionary. How to do that?</p>
  
  <pre><code>&lt;Style TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}"&gt;
      &lt;Setter Property="Background" Value="{StaticResource Primary}" /&gt;
      &lt;Setter Property="Foreground" Value="{StaticResource White}" /&gt;
      &lt;Setter Property="BorderBrush" Value="{StaticResource PrimaryBorder}"/&gt;
      &lt;Setter Property="BorderThickness" Value="0,1,0,0"/&gt;
      &lt;Setter Property="Padding" Value="5,0,5,0"/&gt;
  
      &lt;Setter Property="Template"&gt;
          &lt;Setter.Value&gt;
              &lt;ControlTemplate TargetType="{x:Type Button}"&gt;
                  &lt;Grid SnapsToDevicePixels="True"&gt;
                      &lt;Border x:Name="BkgBorder" CornerRadius="3" BorderThickness="{TemplateBinding BorderThickness}"
                              BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" Opacity="1"&gt;
                      &lt;/Border&gt;
  
                      &lt;ContentPresenter Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True"/&gt;
  
                  &lt;/Grid&gt;
  
                  &lt;ControlTemplate.Triggers&gt;
                      &lt;Trigger Property="IsFocused" Value="True"&gt;
                          &lt;Setter Property="Background" Value="{StaticResource PrimaryFocused}" TargetName="BkgBorder"/&gt;
                          &lt;Setter Property="BorderBrush" Value="{StaticResource PrimaryBorderFocused}" TargetName="BkgBorder"/&gt;
                      &lt;/Trigger&gt;
                      &lt;MultiTrigger&gt;
                          &lt;MultiTrigger.Conditions&gt;
                              &lt;Condition Property="IsMouseOver" Value="True"/&gt;
                              &lt;Condition Property="IsEnabled" Value="True"/&gt;
                          &lt;/MultiTrigger.Conditions&gt;
                          &lt;Setter Property="Background" Value="{StaticResource PrimaryHover}" TargetName="BkgBorder"/&gt;
                          &lt;Setter Property="BorderBrush" Value="{StaticResource PrimaryBorderHover}" TargetName="BkgBorder"/&gt;
                      &lt;/MultiTrigger&gt;
                      &lt;MultiTrigger&gt;
                          &lt;MultiTrigger.Conditions&gt;
                              &lt;Condition Property="IsPressed" Value="True"/&gt;
                              &lt;Condition Property="IsEnabled" Value="True"/&gt;
                          &lt;/MultiTrigger.Conditions&gt;
                          &lt;Setter Property="Background" Value="{StaticResource PrimaryActive}" TargetName="BkgBorder"/&gt;
                          &lt;Setter Property="BorderBrush" Value="{StaticResource PrimaryBorderActive}" TargetName="BkgBorder"/&gt;
                      &lt;/MultiTrigger&gt;
                      &lt;Trigger Property="IsEnabled" Value="False"&gt;
                          &lt;Setter Property="Foreground" Value="{StaticResource White}"/&gt;
                      &lt;/Trigger&gt;
  
                  &lt;/ControlTemplate.Triggers&gt;
              &lt;/ControlTemplate&gt;
          &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
  &lt;/Style&gt;
  </code></pre>
  
  <p>and class</p>
  
  <pre><code>class Buttons
  {
      public static SolidColorBrush GetHoverColor(DependencyObject obj)
      {
          return (SolidColorBrush)obj.GetValue(HoverColorProperty);
      }
  
      public static void SetHoverColor(DependencyObject obj, SolidColorBrush value)
      {
          obj.SetValue(HoverColorProperty, value);
      }
  
      public static readonly DependencyProperty HoverColorProperty =
          DependencyProperty.RegisterAttached("HoverColor", typeof(SolidColorBrush), typeof(MainWindow), new PropertyMetadata(new SolidColorBrush(Colors.Green)));
  
  }
  </code></pre>