title: WPF: Tabbing into a Popup within a UserControl
body: <p>I have a custom control that is a basic sign-in toggle button with a popup. For simplicity's sake, it's here represented as simply having a ListView and a Button. How can I make the contents of the popup tabbable, and respect the overall tab order of the outside control it exists in?</p>
  <p>If my Custom UserControl is defined as such:</p>
  <pre><code>&lt;UserControl x:Name=&quot;root&quot; x:Class=&quot;namespace:CustomUserControl&quot;&gt;
      &lt;DockPanel&gt;
          &lt;ToggleButton x:Name=&quot;ToggleBtn&quot; TabIndex=&quot;{Binding ElementName=root, Path=TabIndex}&quot; /&gt;
          &lt;Popup PlacementTarget=&quot;{Binding ElementName=ToggleBtn}&quot; IsOpen=&quot;{Binding ElementName=ToggleBtn, Path=IsChecked}&quot; StaysOpen=&quot;False&quot;&gt;
              &lt;ListView x:Name=&quot;ListView&quot; TabIndex=&quot;1&quot; /&gt; // I want these to be tabbable
              &lt;Button x:Name=&quot;CustomBtn&quot; TabIndex=&quot;2&quot; /&gt; 
          &lt;/Popup&gt;
      &lt;/DockPanel&gt;
  &lt;/UserControl&gt;
  </code></pre>
  <p>And I'm using it in another control, such as:</p>
  <pre><code>
  &lt;Window&gt;
    &lt;StackPanel&gt;
      &lt;Button x:Name=&quot;Btn1&quot; TabIndex=&quot;1&quot; /&gt;
      &lt;namespace:CustomUserControl x:Name=&quot;customControl&quot; TabIndex=&quot;2&quot; /&gt;
      &lt;Button x:Name=&quot;Btn2&quot; TabIndex=&quot;2&quot; /&gt;
    &lt;/StackPanel&gt;
  &lt;/Window&gt;
  </code></pre>
  <p>I would like the order to be:</p>
  <ol>
  <li>Btn1</li>
  <li>ToggleBtn</li>
  <li>ListView</li>
  <li>CustomBtn</li>
  <li>Btn2</li>
  </ol>
  <p>Is this possible to do? Some possible solutions I've thought, are to be capture when the Popup is opened, and set the keyboard focus on the first element. When the last element loses keyboard focus, the Popup could be closed and the tab index could be incremented.</p>