title: WPF Tab Control override template for individual tab content
body: <p>I have a tab control with some static tabs. However I would also like to add some additional tabs dynamically. Therefore, I defined a header template (using TabControl.ItemTemplate) and a content template (using TabControl.ContentTemplate). However, the static tabs will be showing different content, and therefore I set the individual Tab Item's content template. For some reason however, the Item's content template which I created to set the tab's content is also applying to the header.</p>
  
  <p>You can see from the attached screenshot and code, that while the tab header is set to 'Emails', the tab content is showing up in both the header and the content section.</p>
  
  <p>Please let me know if you need further clarification.</p>
  
  <pre><code>&lt;TabControl Name="ResultsTabControl" SelectionChanged="Selector_OnSelectionChanged" Margin="-2,2" SelectedIndex="{Binding SelectedResultsTab, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"&gt;
  
  &lt;TabControl.Resources&gt;
      &lt;Style TargetType="TabItem" BasedOn="{StaticResource AccentedMetroTabItemStyle}"&gt;&lt;/Style&gt;
  &lt;/TabControl.Resources&gt;
  
  &lt;TabControl.ItemTemplate&gt;
      &lt;DataTemplate&gt;
          &lt;TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType={x:Type TabItem}}, Path=Header}" /&gt;
      &lt;/DataTemplate&gt;
  &lt;/TabControl.ItemTemplate&gt;
  
  &lt;TabControl.ContentTemplate&gt;
      &lt;DataTemplate&gt;
          &lt;TextBlock Text="Testing"/&gt;
      &lt;/DataTemplate&gt;
  &lt;/TabControl.ContentTemplate&gt;
  
  &lt;TabItem Name="EmailListTab" Header="Emails" Style="{StaticResource AccentedMetroTabItemStyle}"&gt;
      &lt;TabItem.ContentTemplate&gt;
          &lt;DataTemplate&gt;
                  &lt;TextBlock Text="My Emails Tab"/&gt;
          &lt;/DataTemplate&gt;
      &lt;/TabItem.ContentTemplate&gt;
  &lt;/TabItem&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>&lt;Style x:Key="AccentedMetroTabItemStyle" TargetType="{x:Type TabItem}"&gt;
      &lt;Setter Property="Padding" Value="2 1 2 1" /&gt;
      &lt;Setter Property="Template"&gt;
          &lt;Setter.Value&gt;
              &lt;ControlTemplate TargetType="{x:Type TabItem}"&gt;
                  &lt;Border x:Name="Border"
                          HorizontalAlignment="Stretch"
                          Background="{TemplateBinding Background}"
                          BorderBrush="{TemplateBinding BorderBrush}"
                          BorderThickness="{TemplateBinding BorderThickness}"
                          SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"&gt;
                      &lt;StackPanel HorizontalAlignment="Stretch" Orientation="Vertical"&gt;
                          &lt;StackPanel Margin="{TemplateBinding Padding}" Orientation="Horizontal"&gt;
                              &lt;controls1:ContentControlEx x:Name="ContentSite"
                                                         Margin="0 2 2 0"
                                                         Padding="{TemplateBinding Padding}"
                                                         Foreground="{TemplateBinding Foreground}"
                                                         FontSize="15"
                                                         FontWeight="{TemplateBinding controls1:ControlsHelper.HeaderFontWeight}"
                                                         FontStretch="{TemplateBinding controls1:ControlsHelper.HeaderFontStretch}"
                                                         Content="{TemplateBinding Header}"
                                                         ContentCharacterCasing="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(controls1:ControlsHelper.ContentCharacterCasing)}"
                                                         ContentStringFormat="{TemplateBinding ContentStringFormat}"
                                                         ContentTemplate="{TemplateBinding ContentTemplate}"
                                                         ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"
                                                         RecognizesAccessKey="True"
                                                         SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /&gt;
                           &lt;/StackPanel&gt;
                          &lt;Rectangle x:Name="Underline"
                                     Height="2"
                                     Margin="0 1 0 0"
                                     HorizontalAlignment="Stretch"
                                     Visibility="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TabControl}}, Path=(controls1:TabControlHelper.IsUnderlined), Converter={StaticResource BooleanToVisibilityConverter}}" /&gt;
                      &lt;/StackPanel&gt;
                  &lt;/Border&gt;
                  &lt;ControlTemplate.Triggers&gt;
  
                      &lt;Trigger Property="IsSelected" Value="true"&gt;
                          &lt;Setter TargetName="ContentSite" Property="TextElement.Foreground" Value="{DynamicResource AccentColorBrush}" /&gt;
                          &lt;Setter TargetName="Underline" Property="Fill" Value="{DynamicResource AccentColorBrush}" /&gt;
                      &lt;/Trigger&gt;
                      &lt;Trigger Property="IsSelected" Value="false"&gt;
                          &lt;Setter TargetName="ContentSite" Property="TextElement.Foreground" Value="{DynamicResource GrayNormalBrush}" /&gt;
                          &lt;Setter TargetName="Underline" Property="Fill" Value="{DynamicResource GrayNormalBrush}" /&gt;
                      &lt;/Trigger&gt;
                      &lt;Trigger SourceName="ContentSite" Property="IsMouseOver" Value="True"&gt;
                          &lt;Setter TargetName="ContentSite" Property="TextElement.Foreground" Value="{DynamicResource GrayHoverBrush}" /&gt;
                           &lt;Setter TargetName="Underline" Property="Fill" Value="{DynamicResource GrayHoverBrush}" /&gt;
                      &lt;/Trigger&gt;
                      &lt;MultiTrigger&gt;
                          &lt;MultiTrigger.Conditions&gt;
                              &lt;Condition SourceName="ContentSite" Property="IsMouseOver" Value="True" /&gt;
                              &lt;Condition Property="IsSelected" Value="True" /&gt;
                          &lt;/MultiTrigger.Conditions&gt;
                          &lt;Setter TargetName="ContentSite" Property="TextElement.Foreground" Value="{DynamicResource HighlightBrush}" /&gt;
                          &lt;Setter TargetName="Underline" Property="Fill" Value="{DynamicResource HighlightBrush}" /&gt;
                      &lt;/MultiTrigger&gt;
                  &lt;/ControlTemplate.Triggers&gt;
              &lt;/ControlTemplate&gt;
          &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
  &lt;/Style&gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/UJn5U.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UJn5U.png" alt="TabControl"></a></p>