title: How to change selected tab on Button click in WPF TabControl with Buttons in Header
body: <p>I have a WPF <code>TabControl</code> that has a couple of buttons in the <code>TabItem</code> header.
  I want the selected tab to change when a headered button is clicked. Here
  is a code snippet:</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;Grid&gt;
        &lt;TabControl&gt;
           &lt;TabItem Content="Item 1 Content"&gt;
              &lt;TabItem.Header&gt;
                 &lt;StackPanel Orientation="Vertical"&gt;
                    &lt;TextBlock FontSize="14" FontWeight="Bold" Text="Item1"/&gt;
                    &lt;StackPanel Orientation="Horizontal"&gt;
                       &lt;Button Content="Action 1"/&gt;
                       &lt;Button Content="Action 2"/&gt;
                    &lt;/StackPanel&gt;
                 &lt;/StackPanel&gt;
              &lt;/TabItem.Header&gt;
           &lt;/TabItem&gt;
           &lt;TabItem Content="Item 2 Content"&gt;
              &lt;TabItem.Header&gt;
                 &lt;StackPanel Orientation="Vertical"&gt;
                    &lt;TextBlock FontSize="14" FontWeight="Bold" Text="Item2"/&gt;
                    &lt;StackPanel Orientation="Horizontal"&gt;
                       &lt;Button Content="Action 1"/&gt;
                       &lt;Button Content="Action 2"/&gt;
                    &lt;/StackPanel&gt;
                 &lt;/StackPanel&gt;
              &lt;/TabItem.Header&gt;
           &lt;/TabItem&gt;
        &lt;/TabControl&gt;
     &lt;/Grid&gt;
  &lt;/Page&gt;
  </code></pre>
  
  <p>This sample show a couple of <code>Tab</code>s. A tab is selected if the header background is clicked, however, if a button is clicked the tab is not selected. I want the button to accept the click but I also want the tab corresponding to the button to get selected. Can anyone help?</p>
  
  <p>Thanks,
  Hitesh</p>