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 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 where the UI framework/platform integrates UI Automation support for control types and control patterns.
This topic contains the following sections.
- Typical Tree Structure
- Relevant Properties
- Required Control Patterns
- Required Events
- Legacy Issues
- Related topics
The following table depicts a typical control and 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|
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.
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 Retrieving Properties from UI Automation Elements.
|UI Automation Property||Value||Notes|
|UIA_AutomationIdPropertyId||See notes.||The value of this property must be unique among all peer elements in the raw view of the UI Automation tree. Allocate the AutomationId property for a menu item if the element is known to be consistent across different instances of the user interface. If the menu item is dynamically populated and not predictable, leave the AutomationId property blank.|
|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 the element performs specialized hit testing, override and provide a clickable point.|
|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_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||See notes.||The name of the menu item control is the text used to label it.|
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.
|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.|
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_BoundingRectanglePropertyId property-changed event.|
|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_ToggleToggleStatePropertyId property-changed event.||If the control supports the Toggle control pattern, it must support this event.|
For Microsoft 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.