Share via


AutomationPeer.GetAcceleratorKey Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets the accelerator key combination for the object that is associated with the UI Automation peer.

Namespace:  System.Windows.Automation.Peers
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Public Function GetAcceleratorKey As String
public string GetAcceleratorKey()

Return Value

Type: System.String
The accelerator key combination hint string.

Remarks

This implementation does nothing more than calling GetAcceleratorKeyCore from the specific peer where GetAcceleratorKey is invoked.

Silverlight does not support accelerator keys directly as a high-level input model. If a control implementation responds to keyboard events to provide key access/accelerator behavior as part of its built-in code handling, the peer for the control should specify a string that contains the keyboard accelerator key combination. To actually handle the key combination, the control should have built-in key handling logic, which is typically implemented by overriding OnKeyDown(KeyEventArgs) or OnKeyUp(KeyEventArgs) and writing specific logic for the indicated key combination. Alternatively, usercode for a control instances could define handlers for KeyDown or KeyUp.

If a control has an accelerator key that is reported as part of the related peer implementation, this means that the control has a singular action or a primary action that can be invoked when the user presses the indicated key or key combination on the keyboard. Specific implementations of GetAcceleratorKeyCore in Silverlight controls are relatively rare. Most of the existing implementations are addressing containment scenarios: making sure that a contained item can forward its own accelerator key information to the level of the container. An example of an implementation that does this is ItemAutomationPeer.GetAcceleratorKeyCore().

Rather than specifying accelerator keys as built-in control behaviors, it is more common for Silverlight application usercode to specify the accelerators that are relevant to control instances as used in a specific Silverlight application UI. In this case, accelerator keys are specified by setting the attached property AutomationProperties.AcceleratorKey on that control instance. This is typically done in the XAML that defines the UI.

The difference between access keys and accelerator keys is as follows. Access keys are primarily for menu items and are generally specified as a single letter. That letter is underlined in a typical menu's visual appearance. Accelerators are usually valid whenever the control has focus, and are not limited to menu concepts or the fact that a menu is open. Note that Silverlight 5 does not have high-level menu API in its core API set.

Important noteImportant Note:

Silverlight is often hosted within a browser. The browser host might not report all possible key events to the Silverlight input system, often because the browser host might handle that key event itself. For details on this concept, see "Browser Hosts and Key Events" section of Keyboard Support.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.