title: How can I get a close button on a templated TabItem in WPF?
body: <p>I have a <code>TabControl</code> where the <code>TabItem</code>s are <code>DataTemplat</code>ed. The template seems to work correctly, in that the usercontrol I want to show in the <code>TabItem</code> is showing correctly.</p>
  
  <p>What I am not sure of is how to get a "x" to show up in the <code>TabItem</code> so I can close each tab, since they are dynamically generated through a template. </p>
  
  <p>Being fairly new to WPF, I am starting to pick up on many of the concepts, but the <code>TabControl</code> gave me a lot of trouble, so I may very well have the template workable, but not maintainable.</p>
  
  <p>This is what I have, and I would like to be able to close each <code>TabControl</code>. I will also need to be able to fire a custom event when that <code>TabControl</code> is closed.</p>
  
  <pre><code>&lt;UserControl x:Class="Russound.Windows.UI.UserControls.CallLog.CaseReaderWpf"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:CallLog="clr-namespace:Russound.Windows.UI.UserControls.CallLog"
      Height="637" Width="505"&gt;
  
      &lt;UserControl.Resources&gt;
          &lt;ResourceDictionary&gt;
              &lt;ResourceDictionary.MergedDictionaries&gt;
                  &lt;ResourceDictionary Source="/Russound.Windows;component/UI/RussoundDictionary.xaml"/&gt;
              &lt;/ResourceDictionary.MergedDictionaries&gt;
          &lt;/ResourceDictionary&gt;
      &lt;/UserControl.Resources&gt;
  
      &lt;TabControl x:Name="tabCases" &gt;
          &lt;TabControl.ItemTemplate&gt;
              &lt;DataTemplate DataType="{x:Type TabItem}"&gt;
                  &lt;StackPanel&gt;
                      &lt;TextBlock Text="{Binding Path=Id}" /&gt;
                  &lt;/StackPanel&gt;
              &lt;/DataTemplate&gt;
          &lt;/TabControl.ItemTemplate&gt;
          &lt;TabControl.ContentTemplate&gt;
              &lt;DataTemplate DataType="{x:Type TabItem}"&gt;
                  &lt;CallLog:CaseReadOnlyDisplay DataContext="{Binding}" /&gt;
              &lt;/DataTemplate&gt;
          &lt;/TabControl.ContentTemplate&gt;
      &lt;/TabControl&gt;
  &lt;/UserControl&gt;
  </code></pre>