InvokePattern.Invoke Méthode

Définition

Envoie une requête pour activer un contrôle et lancer son action unique et non ambiguë.

public:
 void Invoke();
public void Invoke();
member this.Invoke : unit -> unit
Public Sub Invoke ()

Exceptions

L’élément ne prend pas en charge le modèle de InvokePattern contrôle ou est masqué ou bloqué.

L’élément n’est pas activé. Peut être déclenché lorsqu’un fournisseur de UI Automation a implémenté sa propre gestion de la propriété IsEnabled.

Exemples

Dans l’exemple suivant, un InvokePattern modèle de contrôle est obtenu à partir d’un contrôle et la Invoke méthode est appelée.

///--------------------------------------------------------------------
/// <summary>
/// Obtains an InvokePattern control pattern from a control
/// and calls the InvokePattern.Invoke() method on the control.
/// </summary>
/// <param name="targetControl">
/// The control of interest.
/// </param>
///--------------------------------------------------------------------
private void InvokeControl(AutomationElement targetControl)
{
    InvokePattern invokePattern = null;

    try
    {
        invokePattern =
            targetControl.GetCurrentPattern(InvokePattern.Pattern)
            as InvokePattern;
    }
    catch (ElementNotEnabledException)
    {
        // Object is not enabled
        return;
    }
    catch (InvalidOperationException)
    {
        // object doesn't support the InvokePattern control pattern
        return;
    }

    invokePattern.Invoke();
}
'''--------------------------------------------------------------------
''' <summary>
''' Obtains an InvokePattern control pattern from a control
''' and calls the InvokePattern.Invoke() method on the control.
''' </summary>
''' <param name="targetControl">
''' The control of interest.
''' </param>
'''--------------------------------------------------------------------
Private Sub InvokeControl(ByVal targetControl As AutomationElement) 
    Dim invokePattern As InvokePattern = Nothing
    
    Try
        invokePattern = _
        DirectCast(targetControl.GetCurrentPattern(invokePattern.Pattern), _
        InvokePattern)
    Catch e As ElementNotEnabledException
        ' Object is not enabled.
        Return
    Catch e As InvalidOperationException
        ' Object doesn't support the InvokePattern control pattern
        Return
    End Try
    
    invokePattern.Invoke()

End Sub

Remarques

Les appels à Invoke retourner immédiatement sans blocage. Toutefois, ce comportement dépend entièrement de l’implémentation du fournisseur Microsoft UI Automation. Dans les scénarios où l’appel Invoke provoque un problème de blocage (par exemple, une boîte de dialogue modale) un thread d’assistance distinct peut être nécessaire pour appeler la méthode.

S’applique à

Voir aussi