Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I recently fixed this problem for a login splash screen that is being displayed via a storyboard when the main window is first loaded. </p> <p>I believe there were two keys to the fix. One was to make the containing element a focus scope. The other was to handle the Storyboard Completed event for the storyboard that was triggered by the window being loaded. </p> <p>This storyboard makes the username and password canvas visible and then fades into being 100% opaque. The key is that the username control was not visible until the storyboard ran and therefore that control could not get <strong>keyboard</strong> focus until it was visible. What threw me off for awhile was that it had "focus" (i.e. focus was true, but as it turns out this was only logical focus) and I did not know that WPF had the concept of both logical and keyboard focus until reading Kent Boogaart's answer and looking at Microsoft's WPF <a href="http://msdn.microsoft.com/en-us/library/aa969768.aspx" rel="nofollow noreferrer">link text</a></p> <p>Once I did that the solution for my particular problem was straightforward:</p> <p>1) Make the containing element a focus scope</p> <pre><code>&lt;Canvas FocusManager.IsFocusScope="True" Visibility="Collapsed"&gt; &lt;TextBox x:Name="m_uxUsername" AcceptsTab="False" AcceptsReturn="False"&gt; &lt;/TextBox&gt; &lt;/Canvas&gt; </code></pre> <p>2) Attach a Completed Event Handler to the Storyboard</p> <pre><code> &lt;Storyboard x:Key="Splash Screen" Completed="UserNamePassword_Storyboard_Completed"&gt; ... &lt;/Storyboard&gt; </code></pre> <p>and</p> <p>3) Set my username TextBox to have the keyboard focus in the storyboard completed event handler.</p> <pre><code>void UserNamePassword_Storyboard_Completed(object sender, EventArgs e) { m_uxUsername.Focus(); } </code></pre> <p>Note that calling item.Focus() results in the call Keyboard.Focus(this), so you don't need to call this explicitly. See this question about the <a href="https://stackoverflow.com/questions/197088/whats-the-difference-between-keyboard-focusitem-and-item-focus">difference between Keyboard.Focus(item) and item.Focus.</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload