This documentation is archived and is not being maintained.

TextPatternRange.GetAttributeValue Method

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
public Object GetAttributeValue (
	AutomationTextAttribute attribute
public function GetAttributeValue (
	attribute : AutomationTextAttribute
) : Object
Not applicable.



The text attribute.

Return Value

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 typeCondition


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

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0