This documentation is archived and is not being maintained.

TextPattern.FontNameAttribute Field

Identifies the FontName attribute of a text range.

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

public static readonly AutomationTextAttribute FontNameAttribute

Example values for this attribute include "Arial Black" and "Arial Narrow".

The values for this attribute are non-localized.

This identifier is used by UI Automation client applications. UI Automation providers should use the equivalent field in TextPatternIdentifiers.

UI Automation clients get the value of the attribute by calling GetAttributeValue.

Values for this attribute are of type String. The default value is an empty string.

The following example shows how to obtain an attribute value for a range of text in Microsoft Notepad.


Microsoft Notepad is used as the text provider for example purposes only. Microsoft Notepad is not guaranteed to support the attribute value being requested.

/// -------------------------------------------------------------------
/// <summary>
/// Outputs the FontNameAttribute value for a range of text.
/// </summary>
/// <param name="targetTextElement">
/// The AutomationElment that represents a text control.
/// </param>
/// -------------------------------------------------------------------
private void GetFontNameAttribute(AutomationElement targetTextElement)
    TextPattern textPattern = 
        targetTextElement.GetCurrentPattern(TextPattern.Pattern) as TextPattern;

    if (textPattern == null)
        // Target control doesn't support TextPattern.

    // If the target control doesn't support selection then return.
    // Otherwise, get the text attribute for the selected text.
    // If there are currently no selections then the text attribute 
    // will be obtained from the insertion point.
    TextPatternRange[] textRanges;
    if (textPattern.SupportedTextSelection == SupportedTextSelection.None)
        textRanges = textPattern.GetSelection();

    foreach (TextPatternRange textRange in textRanges)
        Object textAttribute =

        if (textAttribute == TextPattern.MixedAttributeValue)
            // Returns MixedAttributeValue if the value of the 
            // specified attribute varies over the text range. 
            Console.WriteLine("Mixed fonts.");
        else if (textAttribute == AutomationElement.NotSupported)
            // Returns NotSupported if the specified attribute is 
            // not supported by the provider or the control. 
                "FontNameAttribute not supported by provider.");

.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.