title: WPF Updating styles at runtime
body: <p>I would like to update the default Window style dynamically at runtime so I can change the FontSize and FontFamily dynamically at runtime. I found that Styles in your resource dictionary are sealed at runtime and cannot be changed, so I used the following method of updating the style:</p>
  
  <pre><code>&lt;Style TargetType="{x:Type Window}"&gt;
      &lt;Setter Property="FontFamily" Value="Arial"/&gt;
      &lt;Setter Property="FontSize" Value="12pt"/&gt;
  &lt;/Style&gt;
  </code></pre>
  
  <p>With the following code:</p>
  
  <pre><code>Style newStyle = (Make a copy of the old style but with the FontSize and FontFamily changed)
  
  // Remove and re-add the style to the ResourceDictionary.
  this.Resources.Remove(typeof(Window));
  this.Resources.Add(typeof(Window), newStyle);
  
  // The style does not update unless you set it on each window.
  foreach (Window window in Application.Current.Windows)
  {
      window.Style = newStyle;
  }
  </code></pre>
  
  <p>There are several problems with this approach and I have a few questions as to why things are the way they are.</p>
  
  <ol>
  <li>Why are styles sealed at runtime and is there a way of making them unsealed?</li>
  <li>When I re-add the new style, why is this not picked up by all of my windows? Why do I have to go and manually apply it to every window?</li>
  <li>Is there a better way?</li>
  </ol>