title: WPF - set focus on textbox
body: <p>In my <code>WPF</code> application I have many text boxes on one page.  I want to set focus on the first text box.  I've Googled it and tried different solutions.</p>
  
  <p>XAML Code :              </p>
  
  <pre><code>&lt;StackPanel Width="350" HorizontalAlignment="Left" &gt;
      &lt;TextBlock x:Name="CustNamelbl" Text="C U S T O M E R  N A M E"
                 Style="{StaticResource LightBoldTxtblkStyle }"/&gt;
      &lt;Grid Height="35"&gt;
           &lt;TextBox x:Name="CustName" Style="{StaticResource Txtbox}"
                    LostFocus="CustName_LostFocus_1"   TabIndex="1"
                    CommandManager.PreviewExecuted="CustName_PreviewExecuted"
                    ContextMenu="{x:Null}" PreviewTextInput="CustName_PreviewTextInput"
                    Margin="0,0,0,0" GotFocus="CustName_GotFocus"/&gt;
           &lt;Rectangle Fill="White" Height="2" Opacity="0.2" 
                      VerticalAlignment="Bottom"&gt;&lt;/Rectangle&gt;
     &lt;/Grid&gt;
  &lt;/StackPanel&gt;   
  </code></pre>
  
  <p>C# Code :</p>
  
  <pre><code>CustName.Focus();
  Keyboard.Focus(CustName);
  </code></pre>
  
  <p>Using this code I am getting <code>Focus</code> on that <code>TextBox</code>.  I'm also able to open system keyboard. However, I am not able to type anything in that <code>TextBox</code>.  Also, that focused cursor is not a blinking cursor, but just a steady cursor. </p>