title: Change a style dynamically in WPF
body: <p>Is there a way to change(and apply) a style dynamically in WPF?</p>
  
  <p>Say I have the style declared in XAML:</p>
  
  <pre><code>    &lt;Style TargetType="local:MyLine" 
             x:Key="MyLineStyleKey" x:Name="MyLineStyleName"&gt;
          &lt;Setter Property="Fill" Value="Pink"/&gt;
          &lt;Style.Triggers&gt;
              &lt;Trigger Property="IsSelected" Value="true"&gt;
                  &lt;Setter Property="Fill" Value="Blue" /&gt;                    
              &lt;/Trigger&gt;
          &lt;/Style.Triggers&gt;
      &lt;/Style&gt;
  </code></pre>
  
  <ol>
  <li><p>In a moment, I need to <strong>change</strong> the <code>Pink</code> color, to, say <code>Green</code>, and all lines with style <code>MyLineStyleKey</code> became Green. A line is Pink when released, and Blue when selected... Now, I needed to change the unselected property(Pink to Green)..., so this is not just setting it to an other color, the trigger (selection>Blue) will not work anymore...Is that possible? How?</p></li>
  <li><p>Is that possible to <strong>bind</strong> to the Pink color in the Style, say, to a Button background, that will reflect the currently used style color?</p></li>
  </ol>
  
  <p>EDIT:<br>
  For <strong>1</strong> I tried:</p>
  
  <pre><code>Style s = (Style)this.Resources["MyLineStyleKey"];
  
  (s.Setters[0] as Setter).Value = background;
  (s.Setters[1] as Setter).Value = background;
  </code></pre>
  
  <p>but an exception occured: </p>
  
  <blockquote>
    <p>After a 'SetterBase' is in use
    (sealed), it cannot be modified.</p>
  </blockquote>