title: Applying WPF styles like CSS and Html
body: <p>I doubt this is possible, but just wanted to confirm.</p>
  
  <p>I am writing a simple WPF application and want my styling to be defined externally, so you could basically load the style as an external resource. A bit like how CSS and HTML are generally separated out...</p>
  
  <p>However one thing that bugs me is that with HTML &amp; CSS its more of an outside looking in approach, the CSS targets the elements and is applied to matching elements. However with WPF it seems that its the other way around, you have to tell the element what styles it should have applied, however this doesn't seem very <em>dynamic</em>. So I just want to know if there is a way to have styles applied so the styles just target the elements.</p>
  
  <p>An example would be something like:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;Style TargetType="{x:Type TextBox}" TargetElement="{x:Name SomeTextboxElement}"&gt;
      &lt;Setter Property="Width" Value="Auto"/&gt;
  &lt;/Style&gt;
  </code></pre>
  
  <p>As normally you have to specify a key with the style, then get the element (SomeTextboxElement) to map to the style's key.</p>
  
  <p>It just seems a bit silly having to explicitly give each element a style binding, it should be more hierarchical and filter down (which may be possible, i just dont know how) and not be a one to one mapping. Would take forever to style a whole application...</p>
  
  <p>Hope that makes sense...</p>