title: How to make a Style generic so I can use it in my entire application?
body: <p>I've search around here on SO and what not able to find a clear answer explaining how to setup a 'style resource'. In my case my dialog controls several buttons and lists, and other various controls which I want to set a generic theme/style for. Similar to how you would do using a CSS file in HTML. </p>
  
  <p>For the sake of simplicity in this example I have a style i want to use across the board on all my buttons. However I would prefer not to contain all these style resources in the xaml of my UI layout. I would like to move the styles to a general xaml resource file which would contain just the styles, that way i could also easily reference them into other wpf dialogs throughout the tool.</p>
  
  <p><strong>How do I set this up to make use of a general resource file containing styles for the various controls in my tool?</strong> Then be able to reference and use that style in my xaml UI's.</p>
  
  <p>Thank you</p>
  
  <pre><code>&lt;Window x:Class="WpfApplication1.MainWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          Title="MainWindow" Height="200" Width="200"&gt;
  
      &lt;Window.Resources&gt;
          &lt;Style TargetType="Button" x:Key="CoolButton" &gt;
              &lt;Setter Property="Margin" Value="1,2,1,2"/&gt;
              &lt;Setter Property="Background" Value="LightBlue"/&gt;
              &lt;Setter Property="HorizontalAlignment" Value="Left"/&gt;
              &lt;Setter Property="FontSize" Value="12" /&gt;
              &lt;Setter Property="FontFamily" Value="Calibri" /&gt;
              &lt;Setter Property="Template"&gt;
                  &lt;Setter.Value&gt;
                      &lt;ControlTemplate TargetType="{x:Type Button}"&gt;
                          &lt;Border Background="{TemplateBinding Background}"
                      BorderBrush="Lavender" BorderThickness="5" CornerRadius="6,0,6,0" x:Name="bd"&gt;
                              &lt;ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                      Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
                      SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" RecognizesAccessKey="True" /&gt;
                          &lt;/Border&gt;
                          &lt;ControlTemplate.Triggers&gt;
                              &lt;Trigger Property="IsMouseOver" Value="True"&gt;
                                  &lt;Setter TargetName="bd" Property="Background" Value="LightGray"/&gt;
                                  &lt;Setter Property="Foreground" Value="White" /&gt;
                                  &lt;Setter Property="Cursor" Value="Hand" /&gt;
                              &lt;/Trigger&gt;
  
                          &lt;/ControlTemplate.Triggers&gt;
                      &lt;/ControlTemplate&gt;
                  &lt;/Setter.Value&gt;
              &lt;/Setter&gt;
          &lt;/Style&gt;
      &lt;/Window.Resources&gt;
  
      &lt;StackPanel&gt;
          &lt;Button Style="{StaticResource CoolButton}" Content="Button" Margin="2" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75"/&gt;
          &lt;Button Style="{StaticResource CoolButton}" Content="Button" Margin="2" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75"/&gt;
          &lt;CheckBox Margin="2" Content="Great"&gt;&lt;/CheckBox&gt;
  
      &lt;/StackPanel&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>On a side note why does this not work to use variables for colors in the resource style xaml?</p>
  
  <pre><code>    &lt;ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;
  
          &lt;!--COLORS--&gt;
          &lt;Color x:Key="AccentColor"&gt;#CC4021&lt;/Color&gt;
  
  
          &lt;Style TargetType="Button"&gt;
              &lt;Setter Property="Foreground" Value="{StaticResource AccentColor}"/&gt;
          &lt;/Style&gt;
  
  &lt;/ResourceDictionary&gt;
  </code></pre>