TextPatternRange.GetAttributeValue(AutomationTextAttribute) Método

Definição

Devolve o valor do atributo especificado em todo o intervalo de texto.

public:
 System::Object ^ GetAttributeValue(System::Windows::Automation::AutomationTextAttribute ^ attribute);
public object GetAttributeValue(System.Windows.Automation.AutomationTextAttribute attribute);
member this.GetAttributeValue : System.Windows.Automation.AutomationTextAttribute -> obj
Public Function GetAttributeValue (attribute As AutomationTextAttribute) As Object

Parâmetros

attribute
AutomationTextAttribute

O atributo texto.

Devoluções

Devolve o valor do atributo especificado. Por exemplo, GetAttributeValue(TextPattern.FontNameAttribute) devolveria uma cadeia que representasse o nome da fonte, se único, do intervalo de texto, enquanto GetAttributeValue(TextPattern.IsItalicAttribute) devolveria um booleano.

Retorna MixedAttributeValue se o valor do atributo especificado variar ao longo do intervalo de texto.

Retorna NotSupported se o atributo especificado não for suportado pelo fornecedor ou pelo controlo.

Exceções

Se o atributo especificado não for válido.

Exemplos

 private Object AttributeValueFromSelection(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 null;
    }
    TextPatternRange[] currentSelection = textpatternPattern.GetSelection();
    // Is 'italic'?
    return currentSelection[0].GetAttributeValue(TextPattern.IsItalicAttribute);
}
Private Function AttributeValueFromSelection(ByVal target As AutomationElement) As Object
    ' 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 Nothing
    End If
    Dim currentSelection As TextPatternRange() = textpatternPattern.GetSelection()
    ' Is 'italic'?
    Return currentSelection(0).GetAttributeValue(TextPattern.IsItalicAttribute)
End Function

Observações

Não há distinção entre texto oculto e visível. Automatização da Interface de Utilizador clientes podem usar IsHiddenAttribute para verificar a visibilidade do texto.

Aplica-se a