Delen via


Eigenschappen retourneren van een UI Automation-provider

Notitie

Deze documentatie is bedoeld voor .NET Framework-ontwikkelaars die de beheerde UI Automation-klassen willen gebruiken die zijn gedefinieerd in de System.Windows.Automation naamruimte. Zie Windows Automation-API: UI Automation voor de meest recente informatie over UI Automation.

Dit onderwerp bevat voorbeeldcode die laat zien hoe een UI Automation-provider eigenschappen van een element naar clienttoepassingen kan retourneren.

Voor een eigenschap die niet expliciet wordt ondersteund, moet de provider (Nothingin Visual Basic) retourneren null . Dit zorgt ervoor dat UI Automation de eigenschap probeert te verkrijgen van een andere bron, zoals de hostvensterprovider.

Voorbeeld

/// <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

Zie ook