UI Automation Support for the MenuItem Control Type

This topic provides information about Microsoft UI Automation support 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.

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 menu item controls, whether Windows Presentation Foundation (WPF), Microsoft Win32, or Windows Forms.

This topic contains the following sections.

Required UI Automation Tree Structure

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 about the UI Automation tree, see UI Automation Tree Overview.

Control View Content View
  • MenuItem "Help"
    • Menu
      • 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 menu item for Help on the menu bar has been added to better illustrate the structure.

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

Required UI Automation Properties

The following table lists the UI Automation properties whose value or definition is especially relevant to the MenuItem control type. For more information about UI Automation properties, see UI Automation Properties for Clients.

UI Automation Property Value Notes
UIA_AutomationIdPropertyId See notes. The value of this property needs to be unique across all controls in an application.
UIA_BoundingRectanglePropertyId See notes. The outermost rectangle that contains the whole control.
UIA_ClickablePointPropertyId See notes. Supported if there is a bounding rectangle. If not every point within the bounding rectangle is clickable, and you perform specialized hit testing, override and provide a clickable point.
UIA_ControlTypePropertyId MenuItem This value is the same for all UI frameworks.
UIA_IsContentElementPropertyId TRUE The menu item control is always included in the content view of the UI Automation tree.
UIA_IsControlElementPropertyId TRUE The menu item control is always included in the control view of the UI Automation tree.
UIA_IsKeyboardFocusablePropertyId See notes. If the control can receive keyboard focus, it must support this property.
UIA_LabeledByPropertyId NULL No label.
UIA_LocalizedControlTypePropertyId See notes. Localized string corresponding to the MenuItem control type. The default value is "menu item" for en-US or English (United States).
UIA_NamePropertyId "Help" The menu item control is included in the content view of the UI Automation tree and is self labeled with a name.

Required UI Automation Control Patterns

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/Pattern Property Support/Value Notes
IExpandCollapseProvider Depends If the control can be expanded or collapsed, implement IExpandCollapseProvider.
IInvokeProvider Depends If the control executes a single action or command, implement IInvokeProvider.
ISelectionItemProvider Depends If the control is used to select from a list of options among menu items, implement ISelectionItemProvider.
IToggleProvider Depends If the control represents an option that can be turned on or off, implement IToggleProvider.

Required UI Automation Events

The following table lists the UI Automation events that menu item controls are required to support. For more information on events, see UI Automation Events Overview.

UI Automation Event Notes
UIA_AutomationFocusChangedEventId None
UIA_BoundingRectanglePropertyId property-changed event. None
UIA_ExpandCollapseExpandCollapseStatePropertyId property-changed event. If the control supports the ExpandCollapse control pattern, it must support this event.
UIA_Invoke_InvokedEventId If the control supports the Invoke control pattern, it must support this event.
UIA_IsEnabledPropertyId property-changed event. If the control supports the IsEnabled property, it must support this event.
UIA_IsOffscreenPropertyId property-changed event. If the control supports the IsOffscreen property, it must support this event.
UIA_SelectionItem_ElementAddedToSelectionEventId If the control supports the SelectionItem control pattern, it must support this event.
UIA_SelectionItem_ElementRemovedFromSelectionEventId If the control supports the SelectionItem control pattern, it must support this event.
UIA_SelectionItem_ElementSelectedEventId If the control supports the SelectionItem control pattern, it must support this event.
UIA_StructureChangedEventId None
UIA_ToggleToggleStatePropertyId property-changed event. If the control supports the Toggle control pattern, it must support this event.

Legacy Issues

For Win32 menu items, the Toggle control pattern is supported only when a menu item is checked and it is possible to programmatically determine whether support for the Toggle control pattern is required. Because a Win32 menu item does not expose whether it can be checked, the Invoke control pattern is supported when the menu item is not checked. The Invoke control pattern is always supported, even for menu items that are only required to support the Toggle control pattern. This is so clients do not become confused when a menu item that was supporting the Invoke control pattern (when the menu item was unchecked) no longer supports that pattern when it becomes checked.

Related Topics

Community Additions

Show: