title: Setting Keyboard Focus on Child Control in TabItem that Is Not Selected
body: <p>I looked through several questions (both in and out of stackoverflow.com) and could not find one that answers my question. If you're aware of one, please let me know.</p>
  
  <p>The scenario is this: I would like to set a control to have keyboard focus when the control is in a TabItem that is not selected. </p>
  
  <p>Sample XAML:</p>
  
  <pre><code>&lt;Window x:Class="WPF_Application1.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;Grid&gt;
          &lt;TabControl&gt;
              &lt;TabItem Name="tab1" Header="tab1"&gt;
                       &lt;Button Name="button" Content="set focus" Height="24" Width="57" Click="button_Click" /&gt;
                  &lt;/TabItem&gt;
              &lt;TabItem Name="tab2" Header="tab2"&gt;
                  &lt;TextBox Name="text" Height="23" Width="331" /&gt;
              &lt;/TabItem&gt;
          &lt;/TabControl&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>Sample XAML code-behind:</p>
  
  <pre><code>namespace WPF_Application1
  {
      /// &lt;summary&gt;
      /// Interaction logic for MainWindow.xaml
      /// &lt;/summary&gt;
      public partial class MainWindow : Window
      {
          public MainWindow()           
          {
              InitializeComponent();
          }
  
          private void button_Click(object sender, RoutedEventArgs e)
          {
              Keyboard.Focus(text); // doesn't work
              text.Focus(); // doesn't work
          }
  
      }
  }
  </code></pre>
  
  <p>Any suggestions? </p>