KeyHandler Element

An event handler that provides keystroke input behavior to a UI object.

Syntax

<KeyHandler
    Command="ICommand object"
    Handle="{true | false}"
    HandlerStage="{Bubbled | Direct | Routed}"
    Key="KeyHandlerKey enumeration"
    Modifiers="{Alt | Control | None | Shift | Windows}"
    Pressing="{true | false}"
    Repeat="{true | false}"
/>

Attributes

Command

An ICommand object associated with the key handler. The invoke method for the command is called when a keystroke event occurs.

Handle

Indicates whether the handler will allow the event to pass on to other event handlers after handling the event. A value of true prevents the event from being passed on to other event handlers, and a value of false allows the event to continue.

HandlerStage

A member of the InputHandlerStage enumeration that indicates the stage in the event handling process when the event will be handled.

Key

Specifies the key to handle events for. This value must be a member of the KeyHandlerKey enumeration.

Modifiers

Modifier that must be pressed along with the key to invoke the command associated with the key handler. This must be a value from the KeyHandlerModifiers enumeration.

Pressing

Indicates whether the key is currently being pressed. This value is read-only.

Note This attribute does not clear its state when its UI loses key focus. For more information, see the Remarks section.

Repeat

Indicates whether the key handler will be invoked multiple times when the key is held down.

Public Instance Events

Event Description
Invoked Notification that is sent for the keystroke event.

Remarks

The Pressing event should be used when you want to change state while a key is being pressed. However, if you want to take an action that is based on a key being pressed, such as navigation, you should use the Invoked event instead. The KeyHandler element maintains a flag that indicates whether the key is currently being pressed. However, if an action such as focus navigation occurs during the Pressing event, the KeyHandler does not update the flag, and it may require two key presses to raise the Pressing event again. For an example of using the Pressing and Invoked events with a KeyHandler, see Working with Input Handlers.

Requirements

Platform: Windows Vista Ultimate, Windows Vista Home Premium, and later

See Also