TextPatternRange.GetAttributeValue Method (AutomationTextAttribute)


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

Namespace:   System.Windows.Automation.Text
Assembly:  UIAutomationClient (in UIAutomationClient.dll)

public object GetAttributeValue(
	AutomationTextAttribute attribute


Type: System.Windows.Automation.AutomationTextAttribute

The text attribute.

Return Value

Type: System.Object

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.

Exception Condition

If the specified attribute is not valid.

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

 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);

.NET Framework
Available since 3.0
Return to top