Compartir a través de


UI Automation Control Patterns for Clients

Actualización: noviembre 2007

This overview introduces control patterns for UI Automation clients. It includes information on how a UI Automation client can use control patterns to access information about the interfaz de usuario (UI).

Control patterns provide a way to categorize and expose a control's functionality independent of the control type or the appearance of the control. UI Automation clients can examine an AutomationElement to determine which control patterns are supported and be assured of the behavior of the control.

For a complete list of control patterns, see Información general acerca de los patrones de control de automatización de la interfaz de usuario.

Este tema contiene las secciones siguientes.

  • Getting Control Patterns
  • Retrieving Properties on Control Patterns
  • Controls with Variable Patterns
  • Temas relacionados

Getting Control Patterns

Clients retrieve a control pattern from an AutomationElement by calling either AutomationElement.GetCachedPattern or AutomationElement.GetCurrentPattern.

Clients can use the GetSupportedPatterns method or an individual IsPatternAvailable property (for example, IsTextPatternAvailableProperty) to determine if a pattern or group of patterns is supported on the AutomationElement. However, it is more efficient to attempt to get the control pattern and test for a null reference than to check the supported properties and retrieve the control pattern since it results in fewer cross-process calls.

The following example demonstrates how to get a TextPattern control pattern from an AutomationElement.

// Specify the control type we're looking for, in this case 'Document'
PropertyCondition cond = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Document);

// target --> The root AutomationElement.
AutomationElement textProvider = target.FindFirst(TreeScope.Descendants, cond);

targetTextPattern = textProvider.GetCurrentPattern(TextPattern.Pattern) as TextPattern;

if (targetTextPattern == null)
{
    Console.WriteLine("Root element does not contain a descendant that supports TextPattern.");
    return;
}

Retrieving Properties on Control Patterns

Clients can retrieve the property values on control patterns by calling either AutomationElement.GetCachedPropertyValue or AutomationElement.GetCurrentPropertyValue and casting the object returned to an appropriate type. For more information on Automatización de la interfaz de usuario properties, see UI Automation Properties for Clients.

In addition to the GetPropertyValue methods, property values can be retrieved through the common language runtime (CLR) accessors to access the Automatización de la interfaz de usuario properties on a pattern.

Controls with Variable Patterns

Some control types support different patterns depending on their state or the manner in which the control is being used. Examples of controls that can have variable patterns are list views (thumbnails, tiles, icons, list, details), Microsoft Excel Charts (Pie, Line, Bar, Cell Value with a formula), Microsoft Word's document area (Normal, Web Layout, Outline, Print Layout, Print Preview), and Microsoft Windows Media Player skins.

Controls implementing custom control types can have any set of control patterns that are needed to represent their functionality.

Vea también

Tareas

Invoke a Control Using UI Automation

Get the Toggle State of a Check Box Using UI Automation

Ejemplo ValuePattern Insert Text

Ejemplo TextPattern Search and Selection

Ejemplo InvokePattern, ExpandCollapsePattern, and TogglePattern

Conceptos

Control Pattern Mapping for UI Automation Clients

Otros recursos

UI Automation Control Patterns

UI Automation Text Pattern