UI Automation Support for the MenuItem Control Type

System_CAPS_ICON_note.jpg Note

This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows Automation API: UI Automation.

This topic provides information about Microsoft UI Automation support for the MenuItem control type. It describes the control's Microsoft UI Automation tree structure and provides the properties and control patterns that are required for the MenuItem control type.

A menu control allows hierarchal organization of elements associated with commands and event handlers. In a typical Microsoft Windows application, a menu bar contains several menu items (such as File, Edit, and Window), and each menu item displays a menu. A menu contains a collection of menu items (such as New, Open, and Close), which can be expanded to display additional menu items or perform a specific action when clicked. A menu item can be hosted in a menu, menu bar, or tool bar.

The following sections define the required UI Automation tree structure, properties, control patterns, and events for the MenuItem control type. The UI Automation requirements apply to all list controls, whether Windows Presentation Foundation (WPF), Win32, or Windows Forms.

The following table depicts the control view and the content view of the UI Automation tree that pertains to menu item controls and describes what can be contained in each view. For more information on the UI Automation tree, see UI Automation Tree Overview.

Control ViewContent View
MenuItem "Help"

  • Menu (sub menu of Help menu item)

    • MenuItem "Help Topics"
    • MenuItem "About Notepad"
MenuItem "Help"

- MenuItem "Help Topics"
- MenuItem "About Notepad"

The control view of the menu item control has the UI Automation tree structure shown above. Note that the Help menu item is inlcluded to better illustrate the structure in a typical menu to submenu hierarchy.

For the content view, Menu is absent from the UI Automation tree because it does not convey meaningful information to the end user.

The following table lists the UI Automation properties whose value or definition is especially relevant to menu item controls. For more information on UI Automation properties, see UI Automation Properties for Clients.

AutomationIdPropertySee notes.The value of this property needs to be unique across all controls in an application.
BoundingRectanglePropertySee notes.The outermost rectangle that contains the whole control.
ClickablePointPropertySee notes.Supported if there is a bounding rectangle. If not every point within the bounding rectangle is clickable, and you perform specialized hit testing, then override and provide a clickable point.
IsKeyboardFocusablePropertySee notes.If the control can receive keyboard focus, it must support this property.
NamePropertySee notes.The menu item control is included in the content view of the UI Automation tree and is self labeled with a name.
LabeledByPropertyNullNo label.
ControlTypePropertyMenuItemThis value is the same for all UI frameworks.
LocalizedControlTypeProperty"menu item"Localized string corresponding to the MenuItem control type.
IsContentElementPropertyTrueThe menu item control is never included in the content view of the UI Automation tree.
IsControlElementPropertyTrueThe menu item control must always be included in the control view of the UI Automation tree.

The following table lists the UI Automation control patterns required to be supported by menu item controls. For more information on control patterns, see UI Automation Control Patterns Overview.

Control Pattern PropertySupportNotes
IExpandCollapseProviderDependsIf the control can be expanded or collapsed, implement IExpandCollapseProvider.
IInvokeProviderDependsIf the control executes a single action or command, implement IInvokeProvider.
IToggleProviderDependsIf the control represents an option that can be turned on or off, implement IToggleProvider.
ISelectionItemProviderDependsIf the control is used to select from a list of options among menu items, implement ISelectionItemProvider.

The following table lists the Microsoft UI Automation events associated with the menu item control.

InvokedEventDependsMust be raised if control supports Invoke control pattern.
ToggleStateProperty property-changed event.DependsMust be raised if control supports Toggle control pattern.
ExpandCollapseStateProperty property-changed event.DependsMust be raised if control supports Expand Collapse control pattern.

The following table lists the UI Automation events required to be supported by all menu item controls. For more information on events, see UI Automation Events Overview.

UI Automation EventSupport/ValueNotes
BoundingRectangleProperty property-changed event.RequiredNone
IsOffscreenProperty property-changed event.RequiredNone
IsEnabledProperty property-changed event.RequiredNone
ExpandCollapseStateProperty property-changed event.DependsNone
ToggleStateProperty property-changed event.DependsNone

Toggle Pattern will only be supported when the Win32 menu item is checked and can be programmatically determined necessary to support Toggle Pattern. Because the Win32 menu item does not expose whether it has the ability to be checked, Invoke Pattern will be supported when the menu item is not checked. An exception will be made to always support Invoke Pattern even for menu items that should only support Toggle Pattern. This is so clients do not become confused that an element that was supporting Invoke Pattern (when menu item was unchecked) no longer supports the pattern once it becomes checked.

UI Automation Control Patterns Overview
UI Automation Control Types Overview
UI Automation Overview