Visão geral de TextPattern e Objetos Embutidos
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 describes how Microsoft UI Automation exposes embedded objects, or child elements, within a text document or container.
Em UI Automation um objeto incorporado é qualquer elemento que tenha limites não textual; Por exemplo, uma imagem, hiperlink, tabela ou tipo de documento, como um Microsoft Excel planilha ou Microsoft Windows Media arquivo. Isso difere da definição padrão, onde um elemento é criado em um aplicativo e incorporado ou vinculado, dentro de outra. Whether the object can be edited within its original application is irrelevant in the context of UI Automation.
Este tópico contém as seguintes seções.
- Embedded Objects and the UI Automation Tree
- Expose Embedded Objects Using TextPattern and TextPatternRange
- Common Scenarios
- Tópicos relacionados
Embedded Objects and the UI Automation Tree
Objetos incorporados são tratados como elementos individuais dentro do modo de exibição do controle da UI Automation árvore. Eles são expostos como filhos do recipiente de texto para que possam ser acessados por meio do mesmo modelam como outros controles em UI Automation.
Example of a Text Container with Table, Image, and Hyperlink Embedded Objects
Example of the Content View for a Portion of the Preceding Text Container
Expose Embedded Objects Using TextPattern and TextPatternRange
Used in conjunction, the TextPattern control pattern class and the TextPatternRange class expose methods and properties that facilitate navigation and querying of embedded objects.
O conteúdo textual (ou texto interno) de um recipiente de texto e um objeto incorporado, como, por exemplo, um hiperlink ou célula de tabela, é exposto como um fluxo de texto único, contínuo, o modo de exibição do controle e a exibição de conteúdo do UI Automation árvore; os limites do objeto são ignorados. Se um o cliente de automação da interface do usuário está recuperando o texto com a finalidade de citando, interpretação ou análise de alguma maneira, o intervalo de texto deve ser verificado para casos especiais, como, por exemplo, uma tabela com objetos incorporados textuais de conteúdo ou outras. Isso pode ser feito chamando GetChildren para obter um AutomationElement para cada incorporada a objeto e depois chamar de RangeFromChild para obter um intervalo de texto para cada elemento. This is done recursively until all textual content has been retrieved.
Example of a text stream with embedded objects and their range spans
When it is necessary to traverse the content of a text range, a series of steps are involved behind the scenes in order for the Move method to execute successfully.
The text range is normalized; that is, the text range is collapsed to a degenerate range at the Start endpoint, which makes the End endpoint superfluous. Essa etapa é necessária para remover a ambigüidade nas situações em que se estende por um intervalo de texto TextUnit limites: Por exemplo, "{A U} RL https://www.microsoft.com está incorporado em texto" onde "{" e "}" é pontos de extremidade do intervalo de texto.
The resulting range is moved backward in the DocumentRange to the beginning of the requested TextUnit boundary.
The range is moved forward or backward in the DocumentRange by the requested number of TextUnit boundaries.
The range is then expanded from a degenerate range state by moving the End endpoint by one requested TextUnit boundary.
Examples of how a text range is adjusted for Move() and ExpandToEnclosingUnit()
Common Scenarios
The following sections present examples of the most common scenarios that involve embedded objects.
Legend for the examples shown:
{ = Start
} = End
Hyperlink
Example 1 - A text range that contains an embedded text hyperlink
{The URL is embedded in text}.
Method called |
Result |
---|---|
Returns the string "The URL https://www.microsoft.com is embedded in text". |
|
Returns the innermost AutomationElement that encloses the text range; in this case, the AutomationElement that represents the text provider itself. |
|
Returns an AutomationElement representing the hyperlink control. |
|
RangeFromChild where AutomationElement is the object returned by the previous GetChildren method. |
Returns the range that represents "http://www.microsoft.com". |
Example 2 - A text range that partially spans an embedded text hyperlink
URL http:// {} é incorporado no texto.
Method called |
Result |
---|---|
Returns the string "www". |
|
Returns the innermost AutomationElement that encloses the text range; in this case, the hyperlink control. |
|
Returns null since the text range doesn't span the entire URL string. |
Example 3 - A text range that partially spans the content of a text container. The text container has an embedded text hyperlink that is not part of the text range.
{The URL} is embedded in text.
Method called |
Result |
---|---|
Returns the string "The URL". |
|
Returns the innermost AutomationElement that encloses the text range; in this case, the AutomationElement that represents the text provider itself. |
|
Move with parameters of (TextUnit.Word, 1). |
Moves the text range span to "http" since the text of the hyperlink is comprised of individual words. In this case, the hyperlink is not treated as a single object. A URL {http} é incorporado no texto. |
Image
Example 1 - A text range that contains an embedded image
{The image is embedded in text}.
Method called |
Result |
---|---|
Returns the string "The is embedded in text". Any ALT text associated with the image cannot be expected to be included in the text stream. |
|
Returns the innermost AutomationElement that encloses the text range; in this case, the AutomationElement that represents the text provider itself. |
|
Returns an AutomationElement representing the image control. |
|
RangeFromChild where AutomationElement is the object returned by the previous GetChildren method. |
Returns the degenerate range that represents "". |
Example 2 - A text range that partially spans the content of a text container. The text container has an embedded image that is not part of the text range.
{The image} is embedded in text.
Method called |
Result |
---|---|
Returns the string "The image". |
|
Returns the innermost AutomationElement that encloses the text range; in this case, the AutomationElement that represents the text provider itself. |
|
Move with parameters of (TextUnit.Word, 1). |
Moves the text range span to "is ". Because only text-based embedded objects are considered part of the text stream, the image in this example does not affect Move or its return value (1 in this case). |
Table
Table used for examples
Cell with Image |
Cell with Text |
---|---|
X |
|
Y |
|
Image for Z |
Z |
Example 1 - Get the text container from the content of a cell.
Method Called |
Result |
---|---|
GetItem with parameters (0,0) |
Returns the AutomationElement representing the content of the table cell; in this case, the element is a text control. |
RangeFromChild where AutomationElement is the object returned by the previous GetItem method. |
Returns the range that spans the image . |
GetEnclosingElement for the object returned by the previous RangeFromChild method. |
Returns the AutomationElement representing the table cell; in this case, the element is a text control that supports TableItemPattern. |
GetEnclosingElement for the object returned by the previous GetEnclosingElement method. |
Returns the AutomationElement representing the table. |
GetEnclosingElement for the object returned by the previous GetEnclosingElement method. |
Returns the AutomationElement that represents the text provider itself. |
Example 2 - Get the text content of a cell.
Method Called |
Result |
---|---|
GetItem with parameters of (1,1). |
Returns the AutomationElement representing the content of the table cell; in this case, the element is a text control. |
RangeFromChild where AutomationElement is the object returned by the previous GetItem method. |
Returns "Y". |
Consulte também
Tarefas
Access Embedded Objects Using UI Automation
Expose the Content of a Table Using UI Automation
Percorrer texto usando automação de interface do usuário
TextPattern Search and Selection Sample