title: WPF ControlTemplate breaks style
body: <p><strong>The stuff that does work</strong></p>
  
  <p>I need to style controls of a certain type that are children of a StackPanel. I'm using:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;StackPanel&gt;
      &lt;StackPanel.Resources&gt;
          &lt;Style TargetType="{x:Type TextBlock}"&gt;...&lt;/Style&gt;
      &lt;/StackPanel.Resources&gt;
      &lt;TextBlock ...&gt;
      ...
  &lt;/StackPanel&gt;
  </code></pre>
  
  <p>And this works fine! Each TextBlock looks to the resources of it's parent (the StackPanel) to find out how it should be styled. It doesn't matter how far down you nest the TextBlock down a StackPanel... if it doesn't find a style in its direct parent, it will look at its parent's parent and so on, until it finds something (in this case, the style that was defined in ).</p>
  
  <p><strong>The stuff that doesn't work</strong></p>
  
  <p>I ran into a problem when I nested a TextBlock inside a ContentControl, which had a Template (see code below). The ControlTemplate seems to disrupt the way a TextBlock retrieves its style from its parents, grandparents,...</p>
  
  <p>The use of a ControlTemplate effectively seems to knock out cold the TextBlock's means of finding its rightful style (the one in StackPanel.Resources). When it encounters a ControlTemplate, it stops looking for its style in the resources up the tree, and instead defaults to the style in MergedDictionaries of the Application itself.</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;StackPanel Orientation="Vertical" Background="LightGray"&gt;
      &lt;StackPanel.Resources&gt;
          &lt;Style TargetType="{x:Type TextBlock}"&gt;
              &lt;Setter Property="Foreground" Value="Green" /&gt;
          &lt;/Style&gt;
      &lt;/StackPanel.Resources&gt;
  
      &lt;TextBlock Text="plain and simple in stackpanel, green" /&gt;
      &lt;ContentControl&gt;
          &lt;TextBlock Text="inside ContentControl, still green" /&gt;
      &lt;/ContentControl&gt;
      &lt;ContentControl&gt;
          &lt;ContentControl.Template&gt;
              &lt;ControlTemplate TargetType="{x:Type ContentControl}"&gt;
                  &lt;StackPanel Orientation="Vertical"&gt;
                      &lt;ContentPresenter /&gt;
                      &lt;TextBlock Text="how come this one - placed in the template - is not green?" /&gt;
                  &lt;/StackPanel&gt;
              &lt;/ControlTemplate&gt;
          &lt;/ContentControl.Template&gt;
          &lt;TextBlock Text="inside ContentControl with a template, this one is green as well" /&gt;
      &lt;/ContentControl&gt;
  
  &lt;/StackPanel&gt;
  </code></pre>
  
  <p>Is there a way - besides duplicating the Style in StackPanel.Resources to ControlTemplate.Resources - to make the TextBlock inside that ControlTemplate find the defined style?</p>
  
  <p>Thanks...</p>