title: DynamicResource for Style BasedOn
body: <p>Building an application that has a custom 'High Contrast' theme for outdoor use that can be toggled on and off during runtime. This works fine by merging and un-merging a resource dictionary that contains styles like below...</p>
  
  <pre><code>&lt;Style x:Key="{x:Type MenuItem}" TargetType="{x:Type MenuItem}"&gt;
      &lt;Setter Property="OverridesDefaultStyle" Value="true"/&gt;
      &lt;Setter Property="FocusVisualStyle" Value="{x:Null}"/&gt;
      &lt;Setter Property="Template" Value="{StaticResource Theme_MenuItemTemplate}"/&gt;
  &lt;/Style&gt;
  </code></pre>
  
  <p>This works great when the usage of a menuitem doesn't specify a style. This isn't realistic though for many situations since there is no way to bind ItemsSource generated children without Styles. For example:</p>
  
  <pre><code>&lt;ContextMenu.ItemContainerStyle&gt;
      &lt;Style TargetType="MenuItem"&gt;
          &lt;Setter Property="Header" Value="{Binding Path=Name}"/&gt;
          &lt;Setter Property="IsCheckable" Value="True"/&gt;
          &lt;Setter Property="IsChecked" Value="{Binding Path=Checked}"/&gt;
          &lt;EventSetter Event="Checked" Handler="HistoryItem_Checked"/&gt;
      &lt;/Style&gt;
  &lt;/ContextMenu.ItemContainerStyle&gt;
  </code></pre>
  
  <p>Every other post on StackOverflow says you just need to do this...</p>
  
  <pre><code>&lt;Style TargetType="MenuItem" BasedOn="{StaticResource {x:Type MenuItem}}"&gt;
      &lt;!-- Your overrides --&gt;
  &lt;/Style&gt;
  </code></pre>
  
  <p>But this doesn't work for my situation because my BasedOn can and will change at runtime (and of course you can't use DynamicResource extension on the BasedOn property). Doing this in my application currently leads to controls that override getting stuck with their style when the control was loaded while every other control correctly switches without reloading.</p>
  
  <p>So my question...</p>
  
  <p>Is there a way to get DynamicResource extension working for BasedOn or is there another method/hack I can implement to get this to work?</p>