title: Binding for WPF Styles
body: <p>I'm trying to create a custom control - a button - which will have multiple styles applied to it depending on the value of a property within the data context.</p>
  
  <p>What I was thinking is using something similar to:</p>
  
  <pre><code>&lt;Button Style="{Binding Path=ButtonStyleProperty, Converter={StaticResource styleConverter}}" Text="{Binding Path=TextProp}" /&gt;
  </code></pre>
  
  <p>And in code... Implement an IValueConverter which does something similar to the code below in the <code>ConvertTo</code> method:</p>
  
  <pre><code>switch(value as ValueEnums)
  {
      case ValueEnums.Enum1:
          FindResource("Enum1ButtonStyle") as Style;
      break;
  
      ... and so on.
  } 
  </code></pre>
  
  <p>However I'm not entirely sure about how to pull out the style object and even if this is possible at all...</p>
  
  <p>What I am doing in the mean time is handling the <code>DataContextChanged</code> event, then attaching a handler to the <code>PropertyChanged</code> event of the object being bound to the button - then running the switch statement in there.</p>
  
  <p>Its not quite perfect but until I can find a better solution it seems like that is what I'll have to use.</p>