


This is the default state for most controls. For more info, see the Shortcut keys example later in this topic.įor a control to receive input focus, it must be enabled, visible, and have IsTabStop and HitTestVisible property values of true. This is necessary when you implement shortcut keys, because keyboard focus is not set by default when your UI loads. You can also call a control's Focus method to force focus. An individual control gains focus when the user clicks or taps directly on that control in the layout, or uses the Tab key to step into a tab sequence within the content area. For more info about how class-based handling of events works (specifically, the "Input event handlers in controls" section), see Events and routed events overview.Ĭontrols in your UI generate keyboard events only when they have input focus. Keys other than Space or Enter still fire KeyDown and KeyUp events. This provides a built-in keyboard equivalent for invoking the button, similar to tapping it with a finger or clicking it with a mouse. When a key press is handled by the control class, the KeyDown and KeyUp events are not raised. For example, the Button class overrides the OnKeyDown events for both the Space key and the Enter key (as well as OnPointerPressed) and routes them to the Click event of the control. Typically, this subset of keys is processed by the class handler to provide built in support of basic keyboard accessibility. In these cases, it might appear that an input event doesn't occur because your event listener doesn't invoke the associated handler. Some XAML controls handle input events internally.
