title: WPF Some styles not applied on DataTemplate controls
body: <p>I am trying to learn something about WPF and I am quite amazed by its flexibility.</p>
  
  <p>However, I have hit a problem with <code>Style</code>s and <code>DataTemplate</code>s, which is little bit confusing.
  I have defined below test page to play around a bit with styles etc and found that the <code>Style</code>s defined in <code>&lt;Page.Resources&gt;</code> for <code>Border</code> and <code>TextBlock</code> are not applied in the <code>DataTemplate</code>, but <code>Style</code> for <code>ProgressBar</code> defined in exactly the same way is applied.</p>
  
  <p>Source code (I just use Kaxaml and XamlPadX to view the result)</p>
  
  <pre><code>&lt;Page
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;
  
    &lt;Page.Resources&gt;
  
      &lt;Style TargetType="{x:Type Border}"&gt;
        &lt;Setter Property="Background" Value="SkyBlue"/&gt;
        &lt;Setter Property="BorderBrush" Value="Black"/&gt;
        &lt;Setter Property="BorderThickness" Value="2"/&gt;
        &lt;Setter Property="CornerRadius" Value="5"/&gt;
      &lt;/Style&gt;
  
      &lt;Style TargetType="{x:Type TextBlock}"&gt;
        &lt;Setter Property="FontWeight" Value="Bold"/&gt;
      &lt;/Style&gt;
  
      &lt;Style TargetType="{x:Type ProgressBar}"&gt;
        &lt;Setter Property="Height" Value="10"/&gt;
        &lt;Setter Property="Width" Value="100"/&gt;
        &lt;Setter Property="Foreground" Value="Red"/&gt;
      &lt;/Style&gt;
  
      &lt;XmlDataProvider x:Key="TestData" XPath="/TestData"&gt;
        &lt;x:XData&gt;
          &lt;TestData xmlns=""&gt;
            &lt;TestElement&gt;
              &lt;Name&gt;Item 1&lt;/Name&gt;
              &lt;Value&gt;25&lt;/Value&gt;
            &lt;/TestElement&gt;
            &lt;TestElement&gt;
              &lt;Name&gt;Item 2&lt;/Name&gt;
              &lt;Value&gt;50&lt;/Value&gt;
            &lt;/TestElement&gt;
          &lt;/TestData&gt;
        &lt;/x:XData&gt;
      &lt;/XmlDataProvider&gt;
  
      &lt;HierarchicalDataTemplate DataType="TestElement"&gt;
        &lt;Border Height="45" Width="120" Margin="5,5"&gt;
          &lt;StackPanel Orientation="Vertical" Margin="5,5" VerticalAlignment="Center" HorizontalAlignment="Center"&gt;
            &lt;TextBlock HorizontalAlignment="Center" Text="{Binding XPath=Name}"/&gt;
            &lt;ProgressBar Value="{Binding XPath=Value}"/&gt;
          &lt;/StackPanel&gt;
        &lt;/Border&gt;
      &lt;/HierarchicalDataTemplate&gt;
  
    &lt;/Page.Resources&gt;
  
    &lt;StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center"&gt;
      &lt;StackPanel Orientation="Vertical" VerticalAlignment="Center"&gt;
        &lt;Border Height="45" Width="120" Margin="5,5"&gt;
          &lt;StackPanel Orientation="Vertical" VerticalAlignment="Center" HorizontalAlignment="Center"&gt;
            &lt;TextBlock HorizontalAlignment="Center" Text="Item 1"/&gt;
            &lt;ProgressBar Value="25"/&gt;
          &lt;/StackPanel&gt;
        &lt;/Border&gt;
        &lt;Border Height="45" Width="120" Margin="5,5"&gt;
          &lt;StackPanel Orientation="Vertical" VerticalAlignment="Center" HorizontalAlignment="Center"&gt;
            &lt;TextBlock HorizontalAlignment="Center" Text="Item 2"/&gt;
            &lt;ProgressBar Value="50"/&gt;
          &lt;/StackPanel&gt;
        &lt;/Border&gt;
      &lt;/StackPanel&gt;
      &lt;ListBox Margin="10,10"  Width="140" ItemsSource="{Binding Source={StaticResource TestData}, XPath=TestElement}"/&gt;
    &lt;/StackPanel&gt;
  &lt;/Page&gt;
  </code></pre>
  
  <p>I suspect it has something to do with default styles etc, but more puzzling is why some <code>Style</code>s are applied and some not. I cannot find an easy explanation for above anywhere and thus would like to ask if someone would be kind enough to explain this behaviour in lamens' terms with possible links to technical description, i.e. to MSDN or so.</p>
  
  <p>Thanks in advance for you support!</p>