Export (0) Print
Expand All

Raise Events from a UI Automation Provider

This topic contains example code that shows how to raise an event from a UI Automation provider.

In the following example, a UI Automation event is raised in the implementation of a custom button control. The implementation enables a UI Automation client application to simulate a button click.

To avoid unnecessary processing, the example checks ClientsAreListening to see whether events should be raised.

/// <summary> 
/// Responds to a button click, regardless of whether it was caused by a mouse or 
/// keyboard click or by InvokePattern.Invoke.  
/// </summary> 
private void OnCustomButtonClicked()
{
    // TODO  Perform program actions invoked by the control. 

    // Raise an event. 
    if (AutomationInteropProvider.ClientsAreListening)
    {
        AutomationEventArgs args = new AutomationEventArgs(InvokePatternIdentifiers.InvokedEvent);
        AutomationInteropProvider.RaiseAutomationEvent(InvokePatternIdentifiers.InvokedEvent, this, args);
    }
}
Show:
© 2014 Microsoft