Share via


Dapatkan Properti Elemen UI Automation

Catatan

Dokumentasi ini ditujukan untuk pengembang .NET Framework yang ingin menggunakan kelas UI Automation terkelola yang ditentukan pada namespace System.Windows.Automation. Untuk informasi terbaru tentang UI Automation, lihat API Automasi Windows: Automasi Antarmuka Pengguna.

Topik ini menunjukkan cara mengambil properti elemen UI Automation.

Dapatkan Nilai Properti Saat Ini

  1. TemukanAutomationElement properti siapa yang ingin Anda dapatkan.

  2. Panggil GetCurrentPropertyValue, atau ambil Current struktur properti dan dapatkan nilai dari salah satu anggotanya.

Dapatkan Nilai Properti yang Disimpan di Tembolok.

  1. TemukanAutomationElement properti siapa yang ingin Anda dapatkan. Properti harus ditentukan dalam CacheRequest.

  2. Panggil GetCachedPropertyValue, atau ambil Cached struktur properti dan dapatkan nilai dari salah satu anggotanya.

Contoh

Contoh berikut menunjukkan berbagai cara untuk mengambil properti saat AutomationElementini dari .

void PropertyCallsExample(AutomationElement elementList)
{
    // The following two calls are equivalent.
    string name = elementList.Current.Name;
    name = elementList.GetCurrentPropertyValue(AutomationElement.NameProperty) as string;

    // The following shows how to ignore the default property, which
    //  would probably be an empty string if the property is not supported.
    //  Passing "false" as the second parameter is equivalent to using the overload
    //  that does not have this parameter.
    object help = elementList.GetCurrentPropertyValue(AutomationElement.HelpTextProperty, true);
    if (help == AutomationElement.NotSupported)
    {
        help = "No help available";
    }
    string helpText = (string)help;
}
Sub PropertyCallsExample(ByVal elementList As AutomationElement)
    ' The following two calls are equivalent.
    Dim name As String = elementList.Current.Name
    name = CStr(elementList.GetCurrentPropertyValue(AutomationElement.NameProperty))

    ' The following shows how to ignore the default property, which 
    '  would probably be an empty string if the property is not supported.
    '  Passing "false" as the second parameter is equivalent to using the overload
    '  that does not have this parameter.
    Dim help As Object = elementList.GetCurrentPropertyValue(AutomationElement.HelpTextProperty, True)
    If help Is AutomationElement.NotSupported Then
        help = "No help available"
    End If
    Dim helpText As String = CStr(help)

End Sub

Lihat juga