Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
Previous Versions
.NET Framework 3.0
Class Library
 FindAttribute Method

  Switch on low bandwidth view
This page is specific to
.NET Framework 3.0

Other versions are also available for the following:
TextPatternRange.FindAttribute Method
Returns a text range subset that has the specified attribute value.

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

Visual Basic (Declaration)
Public Function FindAttribute ( _
    attribute As AutomationTextAttribute, _
    value As Object, _
    backward As Boolean _
) As TextPatternRange
Visual Basic (Usage)
Dim instance As TextPatternRange
Dim attribute As AutomationTextAttribute
Dim value As Object
Dim backward As Boolean
Dim returnValue As TextPatternRange

returnValue = instance.FindAttribute(attribute, value, backward)
C#
public TextPatternRange FindAttribute (
    AutomationTextAttribute attribute,
    Object value,
    bool backward
)
C++
public:
TextPatternRange^ FindAttribute (
    AutomationTextAttribute^ attribute, 
    Object^ value, 
    bool backward
)
J#
public TextPatternRange FindAttribute (
    AutomationTextAttribute attribute, 
    Object value, 
    boolean backward
)
JScript
public function FindAttribute (
    attribute : AutomationTextAttribute, 
    value : Object, 
    backward : boolean
) : TextPatternRange
XAML
Not applicable.

Parameters

attribute

The attribute to search for.

value

The attribute value to search for. This value must match the type specified for the attribute.

backward

true if the last occurring text range should be returned instead of the first; otherwise false.

Return Value

A text range having a matching attribute and attribute value; otherwise null (Nothing in Microsoft Visual Basic .NET).

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

NoteNote:

Use DocumentRange to search the entire document.

C#
 private TextPatternRange RangeFromAttribute(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[] currentSelelction = textpatternPattern.GetSelection();
    // Find 'italic' range
    return currentSelelction[0].FindAttribute(TextPattern.IsItalicAttribute, true, false);
}
Visual Basic
Private Function RangeFromAttribute(ByVal target As AutomationElement) As TextPatternRange
    ' 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()
    Return currentSelection(0).FindAttribute(TextPattern.IsItalicAttribute, True, False)
End Function

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
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker