title: Programmatically set focus when a control becomes visible
body: <p>I have an <code>AutoSuggestBox</code> which is only shown when I click a button. When the <code>AutoSuggestBox</code> becomes visible it should also receive focus.</p>
  
  <p>I tried many ways but none of them worked.</p>
  
  <p>The code I have:</p>
  
  <pre><code> &lt;AutoSuggestBox x:Name="AutoSearchBar" 
        HorizontalAlignment="Right" 
        VerticalAlignment="Center" 
        PlaceholderText="Text to find" 
        Visibility="Collapsed"/&gt;
  
   &lt;Button x:Name="searchButton" 
        Visibility="Visible" 
        HorizontalAlignment="Right"
        FontFamily="Segoe MDL2 Assets" 
        Background="Red"
        Content="&amp;#xE094;"
        Click="searchButton_Click"/&gt;
  </code></pre>
  
  <p>Code Behind:</p>
  
  <pre><code>  private void searchButton_Click(object sender, RoutedEventArgs e)
    {
        AutoSearchBar.Visibility = Visibility.Visible;
        searchButton.Visibility = Visibility.Collapsed;
    }
  </code></pre>
  
  <p>I tried to put this in code-behind <code>searchButton_Click</code>, but the <code>AutoSearchBar</code> control only appears and is not focused.</p>
  
  <pre><code>         AutoSearchBar.Focus(FocusState.Keyboard);
           AutoSearchBar.Focus(FocusState.Pointer);
           AutoSearchBar.Focus(FocusState.Programmatic);
  </code></pre>