Focus

As mentioned previously, a UIElement receives keyboard input (and raises keyboard events) only if it has focus. For that to happen, it must first be eligible for focus, which means it must:

Be enabled (IsEnabled=true)

Be visible (Visibility=Visible)

Be hit-testable (HitTestVisible=true)

Be included in tab navigation (IsTabStop=true)

This list of requirements usually isn’t a big burden because the four properties listed are true by default.

Focus can be given only to Controls (indeed, some of the properties in this list are defined only by Control), so keyboard events can’t originate from any UIElement despite being defined by UIElement. They can be handled on non-Control UIElements containing Controls, however, thanks to event bubbling. ...

Get Universal Windows® Apps with XAML and C# Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.