Partilhar via


Padrões de Controle para Clientes de Automação de IU

Observação

Esta documentação destina.Os desenvolvedores do NET Framework que desejam usar o gerenciado UI Automation classes definidas na System.Windows.Automation namespace.As informações mais recentes sobre UI Automation, consulte API de automação do Windows: Automação da interface do usuário.

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 user interface (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 Visão Geral de Padrões de Controle de Automação de Interface de Usuário.

Este tópico contém as seguintes seções.

  • Getting Control Patterns
  • Retrieving Properties on Control Patterns
  • Controls with Variable Patterns
  • Tópicos 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 UI Automation 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 UI Automation 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.

Consulte também

Tarefas

Invocando um Controle Utilizando Automação de IU

Obter o estado Toggle de uma caixa de seleção usando automação de interface do usuário

ValuePattern Insert Text Sample

TextPattern Search and Selection Sample

InvokePattern, ExpandCollapsePattern, and TogglePattern Sample

Conceitos

Mapeamento de Padrão de Controles para Clientes de Automação de IU

Outros recursos

Padrões de controle de automação de interface do usuário

Padrão de Automação de Texto de Interface de Usuário