Export (0) Print
Expand All

AutomationEvent Class

Silverlight

Represents an Automation event.

System.Object
  System.Runtime.InteropServices.Automation.AutomationEvent

Namespace:  System.Runtime.InteropServices.Automation
Assembly:  System.Windows (in System.Windows.dll)

public sealed class AutomationEvent

The AutomationEvent type exposes the following members.

  NameDescription
Public methodSupported by Silverlight for Windows PhoneAddEventHandlerAttaches the specified delegate to the Automation event.
Public methodSupported by Silverlight for Windows PhoneEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows PhoneFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows PhoneMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneRemoveEventHandlerDetaches the specified delegate from the Automation event.
Public methodSupported by Silverlight for Windows PhoneToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Public eventSupported by Silverlight for Windows PhoneEventRaisedOccurs when the Automation event occurs.
Top

This class provides utility members for using managed event handlers to handle Automation events. It is the return value type of the AutomationFactory.GetEvent method.

In Visual Basic, you must use this class to handle Automation events. In C#, you can attach managed event handlers directly to Automation events by using the += syntax, and detach them using the -= syntax. However, in this case, the specified delegate must have a signature that exactly matches the Automation event signature.

Regardless of language, you can handle the EventRaised event without requiring knowledge of the Automation event signatures. The AddEventHandler and RemoveEventHandler methods provide alternatives that do require knowledge of the event signature.

For more information, see AutomationFactory and How to: Use Automation in Trusted Applications. For more information about Automation, see Automation.

NoteNote:

Events with return values are not supported. Additionally, to use C# custom delegates with Automation events that have optional parameters, you must specify default parameter values in the delegate signature. In Visual Basic, delegate parameters cannot be optional, so you must handle the AutomationEvent.EventRaised event instead.

The following code example demonstrates how to handle Automation events.

This example is part of a larger example in How to: Use Automation in Trusted Applications.


private void SearchEmail()
{
    UpdateStatusMessage("Searching Inbox for 'Silverlight'...");

    // The following code demonstrates three ways to handle Automation 
    // events. The first two ways use the AutomationEvent class. 
    // The last two ways require the use of a delegate with 
    // an API signature that matches the Automation event. 

    AutomationEvent searchEvent = AutomationFactory
        .GetEvent(outlook, "AdvancedSearchComplete");

    // The first way: 
    searchEvent.EventRaised += (sender, e) =>
    {
        SearchComplete(e.Arguments[0]);
    };

    // The second way:
    // searchEvent.AddEventHandler(
    //    new AdvancedSearchCompleteDelegate(SearchComplete));

    // The third way:
    // outlook.AdvancedSearchComplete +=
    //    new AdvancedSearchCompleteDelegate(SearchComplete);

    // Begin the search. 
    outlook.AdvancedSearch("Inbox",
        "urn:schemas:mailheader:subject ci_phrasematch 'Silverlight'",
        true, "SubjectSearch");
}

// Required only with the second two ways of handling Automation events. 
private delegate void AdvancedSearchCompleteDelegate(dynamic search);

// To use custom delegates for events with optional parameters, you
// must specify default values in the delegate signature as shown here:
// private delegate void MyEventHandlerDelegate(int i, float f=77);

private void SearchComplete(dynamic search)
{
    List<String> searchResults = new List<String>();
    foreach (dynamic result in search.Results) 
    { 
        searchResults.Add(result.Subject);
    }
    SetResultsList(searchResults);
}


Silverlight

Supported in: 5, 4

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Community Additions

ADD
Show:
© 2014 Microsoft