实现 UI 自动化 SelectionItem 控件模式

注意

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

本主题介绍实现 ISelectionItemProvider的准则和约定,包括有关属性、方法和事件的信息。 本概述的结尾列出了指向其他参考资料的链接。

SelectionItemPattern 控件模式用于支持充当实现 ISelectionProvider的容器控件的独立可选子项的控件。 有关实现此 SelectionItem 控件模式的控件的示例,请参阅 UI 自动化客户端的控件模式映射。

实现准则和约定

在实现 Selection Item 控件模式时,请注意以下准则和约定:

ISelectionItemProvider 必需的成员

以下属性、方法和事件都是实现 ISelectionItemProvider所必需的。

必需的成员 成员类型 备注
IsSelected properties 无
SelectionContainer properties 无
AddToSelection 方法 无
RemoveFromSelection 方法 无
Select 方法 无
ElementSelectedEvent 活动 当选择更改导致单个选定项目时引发。
ElementAddedToSelectionEvent 活动 将项添加到多选容器时引发。
ElementRemovedFromSelectionEvent 活动 从多选容器中移除项时引发。
InvalidatedEvent 活动 在容器中的选项发生重大更改并需要发送多于 ElementSelectedEvent 常量所允许的 ElementRemovedFromSelectionEvent 和 InvalidateLimit 事件时引发。

异常

提供程序必须引发以下异常。

例外类型 条件
InvalidOperationException 尝试下列任一操作时:

- RemoveFromSelection 被调用在一个单一选择的容器中,这个容器已选择了 IsSelectionRequiredProperty = true 和一个元素。
- 在 RemoveFromSelectionIsSelectionRequiredProperty = 且只选择一个元素的多重选择容器中调用 true。
- AddToSelection 在单选容器上调用,其中 CanSelectMultipleProperty = false 和另一个元素已被选择。

另请参阅