共用方式為


TextPatternRange.FindAttribute 方法

定義

傳回具有指定之屬性值的文字範圍子集。

public:
 System::Windows::Automation::Text::TextPatternRange ^ FindAttribute(System::Windows::Automation::AutomationTextAttribute ^ attribute, System::Object ^ value, bool backward);
public System.Windows.Automation.Text.TextPatternRange FindAttribute (System.Windows.Automation.AutomationTextAttribute attribute, object value, bool backward);
member this.FindAttribute : System.Windows.Automation.AutomationTextAttribute * obj * bool -> System.Windows.Automation.Text.TextPatternRange
Public Function FindAttribute (attribute As AutomationTextAttribute, value As Object, backward As Boolean) As TextPatternRange

參數

attribute
AutomationTextAttribute

要搜尋的屬性。

value
Object

要搜尋的屬性值。 這個值必須符合屬性的型別。

backward
Boolean

如果傳回的是最後產生的文字範圍,而不是第一個文字範圍,則為 true;否則為 false

傳回

具有相符屬性和屬性值的文字範圍;否則為 Null (在 Visual Basic 中為 Nothing)。

範例

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

備註

隱藏和可見文字之間沒有區別。 使用者介面自動化用戶端可用來 IsHiddenAttribute 檢查文字可見度。

注意

使用 DocumentRange 來搜尋整個檔。

適用於

另請參閱