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


Tulajdonságok visszaadása egy UI-automatizálás-szolgáltatótól

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 mintakódot tartalmaz, amely bemutatja, hogy egy UI-automatizálás-szolgáltató hogyan adhat vissza egy elem tulajdonságait az ügyfélalkalmazások számára.

Minden olyan tulajdonság esetében, amely nem támogatja kifejezetten, a szolgáltatónak vissza kell adnia null (Nothing a Visual Basicben). Ez biztosítja, hogy UI-automatizálás egy másik forrásból, például a gazdagépablak-szolgáltatótól próbálja meg beolvasni a tulajdonságot.

Példa

/// <summary>
/// Gets provider property values.
/// </summary>
/// <param name="propId">Property identifier.</param>
/// <returns>The value of the property.</returns>
object IRawElementProviderSimple.GetPropertyValue(int propId)
{
    if (propId == AutomationElementIdentifiers.NameProperty.Id)
    {
        return "Custom list control";
    }
    else if (propId == AutomationElementIdentifiers.ControlTypeProperty.Id)
    {
        return ControlType.List.Id;
    }
    else if (propId == AutomationElementIdentifiers.IsContentElementProperty.Id)
    {
        return true;
    }
    else if (propId == AutomationElementIdentifiers.IsControlElementProperty.Id)
    {
        return true;
    }
    else
    {
        return null;
    }
}
''' <summary>
''' Gets provider property values.
''' </summary>
''' <param name="propId">Property identifier.</param>
''' <returns>The value of the property.</returns>
Function GetPropertyValue(ByVal propId As Integer) As Object _
    Implements IRawElementProviderSimple.GetPropertyValue

    If propId = AutomationElementIdentifiers.NameProperty.Id Then
        Return "Custom list control"
    ElseIf propId = AutomationElementIdentifiers.ControlTypeProperty.Id Then
        Return ControlType.List.Id
    ElseIf propId = AutomationElementIdentifiers.IsContentElementProperty.Id Then
        Return True
    ElseIf propId = AutomationElementIdentifiers.IsControlElementProperty.Id Then
        Return True
    Else
        Return Nothing
    End If
End Function 'IRawElementProviderSimple.GetPropertyValue

Lásd még