Menu 控制項類型的 UI 自動化支援UI Automation Support for the Menu Control Type


這份文件適用於想要使用 UI 自動化UI Automation 命名空間中定義之 Managed System.Windows.Automation 類別的 .NET Framework 開發人員。This documentation is intended for .NET Framework developers who want to use the managed UI 自動化UI Automation classes defined in the System.Windows.Automation namespace. 如需 UI 自動化UI Automation的最新資訊,請參閱 Windows Automation API:UI 自動化For the latest information about UI 自動化UI Automation, see Windows Automation API: UI Automation.

本主題提供功能表控制項類型的 Microsoft UI 自動化Microsoft UI Automation 支援相關資訊。This topic provides information about Microsoft UI 自動化Microsoft UI Automation support for the Menu control type. 其中說明控制項的 Microsoft UI 自動化Microsoft UI Automation 樹狀結構,並提供特定控制項案例的屬性和控制項模式。It describes the control's Microsoft UI 自動化Microsoft UI Automation tree structure and provides the properties and control patterns for specific control scenarios.

功能表控制項可將命令和事件處理常式的關聯項目以階層方式組織。A menu control allows hierarchal organization of elements associated with commands and event handlers. 在典型的 Microsoft Windows 應用程式中,功能表列會包含數個功能表按鈕 (例如 [ 檔案]、[編輯] 和 [視窗] ),而每個功能表按鈕會顯示功能表。In a typical Microsoft Windows application, a menu bar contains several menu buttons (such as File, Edit, and Window), and each menu button displays a menu. 功能表又包含一組功能表項目 (例如 [開新檔案] F:System.Windows.Automation.AutomationElementIdentifiers.IsEnabledProperty、[開啟舊檔] UI Automation Properties Overview和 [關閉檔案] TLA#tla_win32),這些項目可展開顯示更多的功能表項目,或在按一下時可執行特定的動作。A menu contains a collection of menu items (such as New, Open, and Close), which can be expanded to display additional menu items or to perform a specific action when clicked.

下列章節會定義功能表控制項類型所需的 UI 自動化UI Automation 樹狀結構、屬性、控制項模式和事件。The following sections define the required UI 自動化UI Automation tree structure, properties, control patterns, and events for the Menu control type. 無論是 UI 自動化UI AutomationWindows Presentation Foundation (WPF)Windows Presentation Foundation (WPF)Win32Win32Windows FormsWindows Forms需求都適用於所有清單控制項。The UI 自動化UI Automation requirements apply to all list controls, whether Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF), Win32Win32, or Windows FormsWindows Forms.

必要的使用者介面自動化樹狀結構Required UI Automation Tree Structure

下表描述功能表控制項之 UI 自動化UI Automation 樹狀結構的控制項檢視和內容檢視,並說明各檢視中可包含的內容。The following table depicts the control view and the content view of the UI 自動化UI Automation tree that pertains to menu controls and describes what can be contained in each view. 如需 UI 自動化UI Automation 樹狀結構的詳細資訊,請參閱 UI Automation Tree OverviewFor more information on the UI 自動化UI Automation tree, see UI Automation Tree Overview.

控制項檢視Control View 內容檢視Content View

-MenuItem (1或多個)- MenuItem (1 or many)
不適用 (除非功能表控制項為非功能表項目之物件父系的內容功能表)Not applicable (unless the menu control is a context menu that is a parent of an object that is not a menu item)

-MenuItem (1或多個)- MenuItem (1 or many)

功能表控制項一律會出現在 UI 自動化UI Automation 樹狀結構的控制項檢視和內容檢視。Menu controls always appear in the control view and the content view of the UI 自動化UI Automation tree. 功能表控制項類別應該顯示於其資訊所參考的控制項下方。Menu control types should appear under the control that their information is referring to. 使用者介面自動化用戶端必須接聽 MenuOpenedEvent ,以確保它們持續取得功能表控制項所傳達的資訊。UI Automation clients must listen for MenuOpenedEvent to ensure that they consistently obtain information conveyed by menu controls. 內容功能表控制項是特殊案例。Context menu controls are a special case. 它們會顯示為桌面的子系。They appear as children of the Desktop.

必要的使用者介面自動化屬性Required UI Automation Properties

下表列出 UI 自動化UI Automation 屬性,其值或定義與功能表控制項類型特別有關。The following table lists the UI 自動化UI Automation properties whose value or definition is especially relevant to the Menu control type. 如需 UI 自動化UI Automation 屬性的詳細資訊,請參閱用戶端的 UI 自動化屬性For more information on UI 自動化UI Automation properties, see UI Automation Properties for Clients.

UI 自動化UI Automation 屬性Property Value 備註Notes
NameProperty 不支援Not Supported 功能表控制項不需要設定 Name 屬性。The menu control does not require a Name property to be set.
LabeledByProperty Null 典型的功能表控制項不預期有標籤。No label is anticipated with a typical menu control.
ControlTypeProperty 功能表Menu 此值與所有使用者介面架構的值相同。This value is the same for all UI frameworks.
IsContentElementProperty FalseFalse 此功能表控制項不會包含在 UI 自動化UI Automation 樹狀結構的內容檢視中。The menu control is not included in the content view of the UI 自動化UI Automation tree.
IsControlElementProperty TrueTrue 此功能表控制項一律包含在 UI 自動化UI Automation 樹狀結構的控制項檢視中。The menu control is always included in the control view of the UI 自動化UI Automation tree.

必要的使用者介面自動化控制項模式Required UI Automation Control Patterns

功能表控制項類型沒有必要的控制項模式。There are no required control patterns for the Menu control type.

必要的使用者介面自動化事件Required UI Automation Events

當功能表控制項出現在畫面時,必須引發 MenuOpenedEventMenu controls must raise MenuOpenedEvent when they appear on the screen. MenuOpenedEvent 將包含控制項的文字。The MenuOpenedEvent will include the text of the control. 當功能表從畫面消失時,必須引發 MenuClosedEventThe MenuClosedEvent must be raised when a menu disappears from the screen.

下表列出所有功能表控制項都必須支援的 UI 自動化UI Automation 事件。The following table lists the UI 自動化UI Automation events required to be supported by all menu controls. 如需事件的詳細資訊,請參閱 UI Automation Events OverviewFor more information on events, see UI Automation Events Overview.

UI 自動化UI Automation 事件Event 支援/值Support/Value 備註Notes
MenuOpenedEvent 必要項Required NoneNone
MenuClosedEvent 必要項Required NoneNone
BoundingRectangleProperty 屬性變更事件。BoundingRectangleProperty property-changed event. 必要項Required NoneNone
IsOffscreenProperty 屬性變更事件。IsOffscreenProperty property-changed event. 必要項Required NoneNone
IsEnabledProperty 屬性變更事件。IsEnabledProperty property-changed event. 必要項Required NoneNone
AutomationFocusChangedEvent 必要項Required NoneNone
StructureChangedEvent 必要項Required NoneNone

請參閱See also