Implementing the UI Automation ExpandCollapse Control Pattern
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows Automation API: UI Automation.
This topic introduces guidelines and conventions for implementing IExpandCollapseProvider, including information about properties, methods, and events. Links to additional references are listed at the end of the overview.
The ExpandCollapsePattern control pattern is used to support controls that visually expand to display more content and collapse to hide content. For examples of controls that implement this control pattern, see Control Pattern Mapping for UI Automation Clients.
When implementing the ExpandCollapse control pattern, note the following guidelines and conventions:
Aggregate controls—built with child objects that provide the UI with expand/collapse functionality—must support the ExpandCollapsePattern control pattern whereas their child elements do not. For example, a combo box control is built with a combination of list box, button, and edit controls, but it is only the parent combo box that must support the ExpandCollapsePattern.
An exception is the menu control, which is an aggregate of individual MenuItem objects. The MenuItem objects can support the ExpandCollapsePattern control pattern, but the parent Menu control cannot. A similar exception applies to the Tree and Tree Item controls.
When the ExpandCollapseState of a control is set to LeafNode, any ExpandCollapsePattern functionality is currently inactive for the control and the only information that can be obtained using this control pattern is the ExpandCollapseState. If any child objects are subsequently added, the ExpandCollapseState changes and ExpandCollapsePattern functionality is activated.
ExpandCollapseState refers to the visibility of immediate child objects only; it does not refer to the visibility of all descendant objects.
Expand and Collapse functionality is control-specific. The following are examples of this behavior.
Calling Expand on a TreeItem may display all descendants or only immediate children.
If calling Expand or Collapse on a control maintains the state of its descendants, a visibility change event should be sent, not a state change event If the parent control does not maintain the state of its descendants when collapsed, the control may destroy all the descendants that are no longer visible and raise a destroyed event; or it may change the ExpandCollapseState for each descendant and raise a visibility change event.
To guarantee navigation, it is desirable for an object to be in the UI Automation tree (with appropriate visibility state) regardless of its parents ExpandCollapseState. If descendants are generated on demand, they may only appear in the UI Automation tree after being displayed for the first time or only while they are visible.