Custom Server API References > Mercury.QTP.WPF.CustomServer Namespace > IUtilityObject Interface > IUtilityObject Interface Methods > AddHandler Method > AddHandler(UIElement,RoutedEvent,Delegate) Method
Adds an event handler for a routed event.

Remarks

If other handlers exist for the event, the handler added with AddHandler is called first.

To add a handler for a routed event, use AddHandler(UIElement,RoutedEvent,Delegate). To add a handler for a non-routed event, use AddHandler(UIElement,String,Delegate). Check the event documentation in MSDN to determine whether it is routed or not.

Handlers added with this method are released by the UFT infrastructure.

Syntax

Visual Basic (Declaration) 
Overloads Overridable Function AddHandler( _
   ByVal src As UIElement, _
   ByVal e As RoutedEvent, _
   ByVal h As Delegate _
) As Boolean
C# 
virtual bool AddHandler( 
   UIElement src,
   RoutedEvent e,
   Delegate h
)

Parameters

src
The control on which to add the event handler. This is generally the IUtilityObject.ApplicationObject but may be a child control or any other control.
e

The event to handle, for example the Calendar.GotFocusEvent for the GotFocus event on a calendar.

h
The event handler.

Example

C#Copy Code
private RoutedEventHandler _hGotFocus;   
RecordInit()   
{   
    _hGotFocus = new RoutedEventHandler(MyCalendar_GotFocus);   
     AddEventHandler(UtilityObject.ApplicationObject, Calendar.GotFocusEvent, _hGotFocus);   
}   
   
void MyCalendar_GotFocus(object sender, RoutedEventArgs e)   
{     
}

See Also