TextPatternRange.GetAttributeValue(AutomationTextAttribute) Method

Definition

Returns the value of the specified attribute across the entire text range.

C#
public object GetAttributeValue(System.Windows.Automation.AutomationTextAttribute attribute);

Parameters

attribute
AutomationTextAttribute

The text attribute.

Returns

Returns the value of the specified attribute. For example, GetAttributeValue(TextPattern.FontNameAttribute) would return a string that represents the font name, if unique, of the text range while GetAttributeValue(TextPattern.IsItalicAttribute) would return a boolean.

Returns MixedAttributeValue if the value of the specified attribute varies over the text range.

Returns NotSupported if the specified attribute is not supported by the provider or the control.

Exceptions

If the specified attribute is not valid.

Examples

C#
 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);
}

Remarks

There is no differentiation between hidden and visible text. UI Automation clients can use IsHiddenAttribute to check text visibility.

Applies to

Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10