Represents an Automation event.
Assembly: System.Windows (in System.Windows.dll)
Thetype exposes the following members.
|AddEventHandler||Attaches the specified delegate to the Automation event.|
|Equals(Object)||Determines whether the specified Object is equal to the current Object. (Inherited from Object.)|
|Finalize||Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)|
|GetHashCode||Serves as a hash function for a particular type. (Inherited from Object.)|
|GetType||Gets the Type of the current instance. (Inherited from Object.)|
|MemberwiseClone||Creates a shallow copy of the current Object. (Inherited from Object.)|
|RemoveEventHandler||Detaches the specified delegate from the Automation event.|
|ToString||Returns a string that represents the current object. (Inherited from Object.)|
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.
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 Sub SearchEmail() UpdateStatusMessage("Searching Inbox for 'Silverlight'...") ' The following code demonstrates three ways to handle Automation ' events. In Visual Basic, all three ways use the AutomationEvent class. searchEvent = AutomationFactory.GetEvent(outlook, "AdvancedSearchComplete") ' The first way is demonstrated by the Handles clause of the ' SearchEvent_EventRaised method, which requires the WithEvents modifier ' on the searchEvent variable declaration. ' The second way uses the AddHandler syntax with the EventRaised event, ' and does not require the WithEvents modifier. ' AddHandler searchEvent.EventRaised, AddressOf SearchEvent_EventRaised ' The third way uses the AutomationEvent.AddEventHandler method, and ' requires the use of a delegate with an API signature that matches the ' Automation event. ' searchEvent.AddEventHandler( ' New AdvancedSearchCompleteDelegate(AddressOf SearchComplete)) ' Begin the search. outlook.AdvancedSearch("Inbox", "urn:schemas:mailheader:subject ci_phrasematch 'Silverlight'", True, "SubjectSearch") End Sub Private WithEvents searchEvent As AutomationEvent Sub SearchEvent_EventRaised(ByVal sender As Object, ByVal e As AutomationEventArgs) Handles searchEvent.EventRaised SearchComplete(e.Arguments(0)) End Sub ' Required only with the second two ways of handling Automation events. ' Private Delegate Sub AdvancedSearchCompleteDelegate(ByRef search As Object) ' Note: Visual Basic does not support the use of custom delegates for ' events with optional parameters. Private Sub SearchComplete(ByRef search As Object) Dim searchResults As New List(Of String) For Each result As Object In search.Results searchResults.Add(result.Subject) Next SetResultsList(searchResults) End Sub
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.