title: TabItem - how to access element in custom HeaderTemplate from TabItem Style Trigger
body: <p>I have following code:</p>
  
  <pre><code>&lt;Window x:Class="kkk.MainWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          Title="MainWindow" Height="350" Width="525"&gt;
      &lt;Window.Resources&gt;
  
          &lt;Style TargetType="{x:Type TabItem}" x:Key="maintemplate"&gt;
  
              &lt;Style.Resources&gt;
                  &lt;DataTemplate x:Key="headertemplate" DataType="{x:Type TabItem}"&gt;
                      &lt;StackPanel Orientation="Horizontal"&gt;
                          &lt;ContentPresenter Content="{Binding RelativeSource={RelativeSource AncestorType={x:Type TabItem} }, Path=Header}"/&gt;
                          &lt;Button Content="X" x:Name="CloseButton"&gt;
                              &lt;Button.LayoutTransform&gt;
                                  &lt;ScaleTransform ScaleX="0.8" ScaleY="0.5"&gt;&lt;/ScaleTransform&gt;
                              &lt;/Button.LayoutTransform&gt;
                          &lt;/Button&gt;
                      &lt;/StackPanel&gt;
                  &lt;/DataTemplate&gt;
              &lt;/Style.Resources&gt;
  
              &lt;Setter Property="HeaderTemplate" Value="{StaticResource headertemplate}"&gt;&lt;/Setter&gt;
  
          &lt;/Style&gt;
  
      &lt;/Window.Resources&gt;
      &lt;Grid&gt;
  
          &lt;TabControl&gt;
              &lt;TabItem Header="tab1" Style="{StaticResource maintemplate}"&gt;&lt;/TabItem&gt;
              &lt;TabItem Header="tab1" Style="{StaticResource maintemplate}"&gt;&lt;/TabItem&gt;
          &lt;/TabControl&gt;
  
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>It creates tabcontrol with small x button on each tabitem header (it will be used to close tab).
  Now I want to hide this button when tab is not selected.
  I tried somwthing like:</p>
  
  <pre><code>&lt;Style.Triggers&gt;
                  &lt;Trigger Property="IsSelected" Value="False"&gt;
                      &lt;Setter Property="????" Value="Visible"&gt;&lt;/Setter&gt;
                  &lt;/Trigger&gt;
              &lt;/Style.Triggers&gt;
  </code></pre>
  
  <p>But I dont know how to access <code>CloseButton</code> from TabItem Style Trigger -> I tried <code>TargetName="CloseButton"</code> but it doesnt work...</p>