Megosztás a következőn keresztül:


UI-automatizálás elem tulajdonságainak lekérése

Feljegyzés

Ez a dokumentáció .NET-keretrendszer fejlesztőknek készült, akik a névtérben System.Windows.Automation meghatározott felügyelt UI-automatizálás osztályokat szeretnék használni. A UI-automatizálás kapcsolatos legfrissebb információkért lásd: Windows Automation API: UI-automatizálás.

Ez a témakör bemutatja, hogyan kérhető le egy UI-automatizálás elem tulajdonságai.

Aktuális tulajdonságérték lekérése

  1. Szerezze be a AutomationElement kívánt ingatlant.

  2. Hívja meg GetCurrentPropertyValue, vagy kérje le a Current tulajdonságstruktúrát, és kérje le az értéket az egyik tagjától.

Gyorsítótárazott tulajdonságérték lekérése

  1. Szerezze be a AutomationElement kívánt ingatlant. A tulajdonságot meg kell adni a CacheRequest.

  2. Hívja meg GetCachedPropertyValue, vagy kérje le a Cached tulajdonságstruktúrát, és kérje le az értéket az egyik tagjától.

Példa

Az alábbi példa egy adott elem aktuális tulajdonságainak lekérésének különböző módjait AutomationElementmutatja be.

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

Lásd még