TextPatternRange.ExpandToEnclosingUnit(TextUnit) Método

Definição

Expande o intervalo de texto para o especificado TextUnit.

public:
 void ExpandToEnclosingUnit(System::Windows::Automation::Text::TextUnit unit);
public void ExpandToEnclosingUnit(System.Windows.Automation.Text.TextUnit unit);
member this.ExpandToEnclosingUnit : System.Windows.Automation.Text.TextUnit -> unit
Public Sub ExpandToEnclosingUnit (unit As TextUnit)

Parâmetros

unit
TextUnit

A unidade textual.

Exemplos

 private void ExpandSelection(AutomationElement target)
{
    // 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);

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

    if (textpatternPattern == null)
    {
        Console.WriteLine("Root element does not contain a descendant that supports TextPattern.");
        return;
    }
    TextPatternRange[] currentSelection = textpatternPattern.GetSelection();
    // Expand selection to include entire document
    currentSelection[0].ExpandToEnclosingUnit(TextUnit.Document);
}
Private Sub ExpandSelection(ByVal target As AutomationElement)
    ' Specify the control type we're looking for, in this case 'Document'
    Dim cond As PropertyCondition = New PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Document)

    ' target --> The root AutomationElement.
    Dim textProvider As AutomationElement = target.FindFirst(TreeScope.Descendants, cond)

    Dim textpatternPattern As TextPattern = CType(textProvider.GetCurrentPattern(TextPattern.Pattern), TextPattern)

    If (textpatternPattern Is Nothing) Then
        Console.WriteLine("Root element does not contain a descendant that supports TextPattern.")
        Return
    End If
    Dim currentSelection As TextPatternRange() = textpatternPattern.GetSelection()
    currentSelection(0).ExpandToEnclosingUnit(TextUnit.Document)
End Sub

Observações

Se o alcance já for uma quantidade exata das unidades especificadas, então mantém-se inalterado.

Para que o ExpandToEnclosingUnit método seja executado com sucesso, é realizada uma sequência de ações nos bastidores.

  1. O intervalo de texto é normalizado; ou seja, o intervalo de texto é colapsado para um intervalo degenerado no Start ponto final, tornando o End ponto final supérfluo. Este passo é necessário para remover ambiguidade em situações em que um intervalo de texto atravessa unit fronteiras; por exemplo, "{O U}RL https://www.microsoft.com/ está incorporado no texto" onde "{" e "}" são os extremos do intervalo de texto.

  2. O intervalo resultante é movido para trás no DocumentRange até o início do limite solicitado unit.

  3. O intervalo é movido para a frente ou para trás no DocumentRange pelo número solicitado de unit limites.

  4. O intervalo é então expandido a partir de um estado degenerado de intervalo, movendo o ponto de extremidade End por um limite unit solicitado.

Ajustes de alcance por Mover & Expandir ParaAjustamentos de Alcance da Unidade Exemplos de como um intervalo de texto é ajustado para Move() e ExpandToEnclosingUnit()

Note

Estes passos são necessários, pois é comum que um leitor de ecrã leia uma palavra inteira, frase ou parágrafo inteiro no ponto de inserção ou em qualquer posição virtual do cursor.

ExpandToEnclosingUnit respeita tanto o texto oculto como o visível. O cliente Automatização da Interface de Utilizador pode verificar o IsHiddenAttribute para a visibilidade do texto.

ExpandToEnclosingUnit adia para o próximo maior TextUnit suporte se o dado TextUnit não for suportado pelo controlo.

A ordem, da menor para a maior, está listada abaixo.

Aplica-se a

Ver também