title: How to Simulate a Tab Key Press with Code in UWP
body: <p>I am trying to use buttons on the screen to perform the function of Tab and reverse Tab. I want the app to tab through the Segment buttons with these other buttons and then the user be able to select one with the Enter key. Trying to make the program fully navigable by keyboard.</p>
  
  <p><img src="https://i.imgur.com/PRhuckf.png" alt="demo layout"></p>
  
  <p>I have tried using a KeyDown event and then directional focus navigation, but I am more looking to have the system simulate a tab key press to follow the tab path.</p>
  
  <p>This is the code I have been trying to far as a work around but it isn't exactly the functionality I want.</p>
  
  <pre><code>        private void Grid_KeyDown(object sender, KeyRoutedEventArgs e)
          {
              DependencyObject candidate = null;
  
              var options = new FindNextElementOptions()
              {
                  SearchRoot = WeldPGrid,
                  XYFocusNavigationStrategyOverride = XYFocusNavigationStrategyOverride.Projection
              };
  
              switch (e.Key)
              {
                  case Windows.System.VirtualKey.Up:
                      candidate =
                          FocusManager.FindNextElement(
                              FocusNavigationDirection.Up, options);
                      break;
                  case Windows.System.VirtualKey.Down:
                      candidate =
                          FocusManager.FindNextElement(
                              FocusNavigationDirection.Down, options);
                      break;
                  case Windows.System.VirtualKey.Left:
                      candidate = FocusManager.FindNextElement(
                          FocusNavigationDirection.Left, options);
                      break;
                  case Windows.System.VirtualKey.Right:
                      candidate =
                          FocusManager.FindNextElement(
                              FocusNavigationDirection.Right, options);
                      break;
              }
              // Also consider whether candidate is a Hyperlink, WebView, or TextBlock.
              if (candidate != null &amp;&amp; candidate is Control)
              {
                  (candidate as Control).Focus(FocusState.Keyboard);
              }
          }
  </code></pre>
  
  <p>As a final result I am looking to put the simulated tab press in a click event or command for the buttons on the side instead of just using the directional keys.
  Any help with this issue would be much appreciated!</p>