UI 自动化属性概述

注释

本文档适用于想要使用 System.Windows.Automation 命名空间中定义的托管 UI 自动化类的 .NET Framework 开发人员。 有关 UI 自动化的最新信息,请参阅 Windows 自动化 API:UI 自动化

UI 自动化提供程序公开Microsoft UI 自动化元素的属性。 这些属性使 UI 自动化客户端应用程序能够发现有关用户界面(UI)部分的信息,尤其是控件,包括静态数据和动态数据。

本部分概述了Microsoft UI 自动化属性。 以下主题提供了更具体的信息:

属性标识符

每个属性都由一个数字和一个名称标识。 属性的名称仅用于调试和诊断。 提供程序使用数字 ID 来标识传入的属性请求。 但是,客户端应用程序仅使用 AutomationProperty封装数字和名称来标识要检索的属性。

AutomationProperty 表示特定属性的对象可用作各种类中的字段。 出于安全原因,UI 自动化提供程序从一组单独的类中获取这些对象,这些类包含在 Uiautomationtypes.dll中。

下表按包含 AutomationPropertyID 的类对属性进行分类。

属性类型 客户端从中获取 ID 提供程序从中获取 ID
所有元素通用的属性(请参阅下表) AutomationElement AutomationElementIdentifiers
停靠窗口的位置 DockPattern DockPatternIdentifiers
可以展开和折叠的元素的状态 ExpandCollapsePattern ExpandCollapsePatternIdentifiers
网格中项的属性 GridItemPattern GridItemPatternIdentifiers
网格的属性 GridPattern GridPatternIdentifiers
具有多个视图的元素的当前和支持视图 MultipleViewPattern MultipleViewPatternIdentifiers
在值范围内移动的元素的属性,例如滑块 RangeValuePattern RangeValuePatternIdentifiers
滚动窗口的属性 ScrollPattern ScrollPatternIdentifiers
可选择的项的状态和容器,如列表中所示 SelectionItemPattern SelectionItemPatternIdentifiers
包含选择项的控件的属性 SelectionPattern SelectionPatternIdentifiers
表中项的列标题和行标题 TableItemPattern TableItemPatternIdentifiers
表的列标题和行标题和方向 TablePattern TablePatternIdentifiers
切换控件的状态 TogglePattern TogglePatternIdentifiers
可移动、旋转或调整大小的元素的功能 TransformPattern TransformPatternIdentifiers
具有值的元素的值和读/写功能 ValuePattern ValuePatternIdentifiers
窗口的功能和状态 WindowPattern WindowPatternIdentifiers

按类别排列的属性

下表对在AutomationElementAutomationElementIdentifiers中找到其 ID 的属性进行分类。 这些属性适用于所有控件。 在提供程序应用程序的生存期内,除了其中的一些属性,它们可能都是静态的;大多数动态属性都与控件模式相关联。

“属性访问”列列出了除GetCurrentPropertyValueGetCachedPropertyValue之外每个属性的其他访问器。 有关在客户端应用程序中获取属性的详细信息,请参阅 客户端的 UI 自动化属性

注释

有关每个属性的具体信息,请点击 属性访问 列中的链接。

显示特征

属性标识符
BoundingRectangleProperty BoundingRectangle
CultureProperty n/a
HelpTextProperty HelpText
IsOffscreenProperty IsOffscreen
OrientationProperty Orientation

元素类型

属性标识符
ControlTypeProperty ControlType
IsContentElementProperty IsContentElement
IsControlElementProperty IsControlElement
ItemTypeProperty ItemType
LocalizedControlTypeProperty LocalizedControlType

标识

属性标识符
AutomationIdProperty AutomationId
ClassNameProperty ClassName
FrameworkIdProperty FrameworkId
LabeledByProperty LabeledBy
NameProperty Name
ProcessIdProperty ProcessId
RuntimeIdProperty GetRuntimeId
NativeWindowHandleProperty NativeWindowHandle

互动

属性标识符
AcceleratorKeyProperty AcceleratorKey
AccessKeyProperty AccessKey
ClickablePointProperty GetClickablePoint
HasKeyboardFocusProperty HasKeyboardFocus
IsEnabledProperty IsEnabled
IsKeyboardFocusableProperty IsKeyboardFocusable

对模式的支持

属性标识符
IsDockPatternAvailableProperty GetSupportedPatterns
IsExpandCollapsePatternAvailableProperty GetSupportedPatterns
IsGridItemPatternAvailableProperty GetSupportedPatterns
IsGridPatternAvailableProperty GetSupportedPatterns
IsInvokePatternAvailableProperty GetSupportedPatterns
IsMultipleViewPatternAvailableProperty GetSupportedPatterns
IsRangeValuePatternAvailableProperty GetSupportedPatterns
IsScrollItemPatternAvailableProperty GetSupportedPatterns
IsScrollPatternAvailableProperty GetSupportedPatterns
IsSelectionItemPatternAvailableProperty GetSupportedPatterns
IsSelectionPatternAvailableProperty GetSupportedPatterns
IsTableItemPatternAvailableProperty GetSupportedPatterns
IsTablePatternAvailableProperty GetSupportedPatterns
IsTextPatternAvailableProperty GetSupportedPatterns
IsTogglePatternAvailableProperty GetSupportedPatterns
IsTransformPatternAvailableProperty GetSupportedPatterns
IsValuePatternAvailableProperty GetSupportedPatterns
IsWindowPatternAvailableProperty GetSupportedPatterns

其他

属性标识符
IsRequiredForFormProperty IsRequiredForForm
IsPasswordProperty IsPassword
ItemStatusProperty ItemStatus

本地化

UI 自动化提供程序应以操作系统语言呈现以下属性:

属性和事件

与 UI 自动化中的属性紧密关联是属性更改事件的概念。 对于动态属性,客户端应用程序需要一种方法来知道属性值已更改,以便它可以更新其信息缓存或以某种其他方式响应新信息。

当 UI 中的某个内容发生更改时,提供程序会引发事件。 例如,如果选中或清除了复选框,则提供程序的 Toggle 模式实现将引发属性更改事件。 提供程序可以有选择地引发事件,具体取决于任何客户端是在侦听事件还是在侦听特定事件。

并非所有属性更改都会引发事件;这完全由元素的 UI 自动化提供程序实现决定。 例如,列表框的标准代理提供程序在 SelectionProperty 更改时不会引发事件。 相反,在这种情况下,应用程序必须侦听 ElementSelectedEvent

客户端通过订阅事件来侦听事件。 订阅事件意味着创建能够处理这些事件的委托方法,并将这些方法和相关特定事件一起传递给 UI 自动化进行处理。 对于属性变更事件,客户端必须实现 AutomationPropertyChangedEventHandler

另请参阅