Bagikan melalui


TextPatternRange.FindAttribute Metode

Definisi

Mengembalikan subset rentang teks yang memiliki nilai atribut yang ditentukan.

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

Parameter

attribute
AutomationTextAttribute

Atribut yang akan dicari.

value
Object

Nilai atribut yang akan dicari. Nilai ini harus cocok dengan jenis yang ditentukan untuk atribut .

backward
Boolean

true jika rentang teks terakhir yang muncul harus dikembalikan alih-alih yang pertama; jika tidak false.

Mengembalikan

Rentang teks yang memiliki atribut dan nilai atribut yang cocok; jika tidak null (Nothing di Visual Basic).

Contoh

 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

Keterangan

Tidak ada diferensiasi antara teks tersembunyi dan terlihat. Klien Automation UI dapat menggunakan IsHiddenAttribute untuk memeriksa visibilitas teks.

Catatan

Gunakan DocumentRange untuk mencari seluruh dokumen.

Berlaku untuk

Lihat juga