Export (0) Print
Expand All

InvokePattern.Invoke Method

Sends a request to activate a control and initiate its single, unambiguous action.

Namespace:  System.Windows.Automation
Assembly:  UIAutomationClient (in UIAutomationClient.dll)

public void Invoke()

ExceptionCondition
InvalidOperationException

The element does not support the InvokePattern control pattern or is hidden or blocked.

ElementNotEnabledException

The element is not enabled. Can be raised when a UI Automation provider has implemented its own handling of the IsEnabled property.

Calls to Invoke should return immediately without blocking. However, this behavior is entirely dependent on the Microsoft UI Automation provider implementation. In scenarios where calling Invoke causes a blocking issue (such as a modal dialog) a separate helper thread may be required to call the method.

In the following example an InvokePattern control pattern is obtained from a control and the Invoke method is called.

///-------------------------------------------------------------------- 
/// <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();
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft