title: WPF: How to apply a controlTemplate to a TabControl's tabItem Header while using Databinding?
body: <p>I have a TabControl which is acquiring tabs and content through DataBinding. Instead of normal Tabs, I wanted Tabs to be of custom shape (say, Ellipse) for all tabs, So I have a ControlTemplate which i want to apply for all tabs.Being new to WPF,I am just confused on how to apply a controlTemplate to a TabControl's tabItem  header while using Databinding?</p>
  
  <pre><code>&lt;Window.Resources&gt;
      &lt;ControlTemplate x:Key="TabItemControlTemplate1" TargetType="{x:Type TabItem}"&gt;
          &lt;Grid SnapsToDevicePixels="True"&gt;
              &lt;Border CornerRadius="12" x:Name="Bd" BorderBrush="Red" BorderThickness="1" Padding="{TemplateBinding Padding}"&gt;
                 &lt;ContentPresenter x:Name="Content" ContentTemplate="{TemplateBinding HeaderTemplate}" Content="{TemplateBinding Header}" ContentStringFormat="{TemplateBinding HeaderStringFormat}" ContentSource="Header" HorizontalAlignment="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type ItemsControl}}}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{Binding VerticalContentAlignment, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type ItemsControl}}}"/&gt;
              &lt;/Border&gt;
          &lt;/Grid&gt;
  
      &lt;/ControlTemplate&gt;
  &lt;/Window.Resources&gt;
  
  &lt;Grid x:Name="LayoutRoot"&gt;
       &lt;TabControl
      ItemsSource="{Binding CarCollection}"&gt;
                  &lt;TabControl.ItemTemplate&gt;
                      &lt;!-- this is the header template--&gt;
                      &lt;DataTemplate&gt;
                          &lt;TextBlock
                  Text="{Binding DisplayName}" /&gt;
                      &lt;/DataTemplate&gt;
                  &lt;/TabControl.ItemTemplate&gt;
                  &lt;TabControl.ContentTemplate&gt;
                      &lt;!-- this is the body of the TabItem template--&gt;
                      &lt;DataTemplate&gt;
                          &lt;ContentControl
                  Content="{Binding Value}" /&gt;
                      &lt;/DataTemplate&gt;
                  &lt;/TabControl.ContentTemplate&gt;
              &lt;/TabControl&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p></p>
  
  <p>In those cases where databinding is not used, I know how to apply it. Issue is when Databinding is used, I am able to achieve this through the below code.</p>
  
  <pre><code>&lt;TabControl HorizontalAlignment="Left" Height="224" Margin="72,66,0,0" VerticalAlignment="Top" Width="412"&gt;
          &lt;TabItem Header="TabItem" Template="{DynamicResource TabItemControlTemplate1}" Height="19.96" VerticalAlignment="Top"&gt;
              &lt;Grid Background="#FFE5E5E5"/&gt;
          &lt;/TabItem&gt;
          &lt;TabItem Header="TabItem"&gt;
              &lt;Grid Background="#FFE5E5E5"/&gt;
          &lt;/TabItem&gt;
      &lt;/TabControl&gt;
  </code></pre>
  
  <p>Any help on this?</p>