CreateDelegate(class,class::method) (Compact 2013)

3/28/2014

This function creates a delegate for an event. The delegate represents the event handler that you specify in the parameters.

Syntax

template <class T, typename ArgType, typename SenderType>
IXRDelegate<ArgType, SenderType>* CreateDelegate(
    T* pT, 
    HRESULT (T::*pfn)(SenderType*, ArgType*)
)

Parameters

  • pT
    [in] Handle to an instance of a custom handler object that implements the event handler.
  • T::*pfn
    [in] Handle to a method in the custom handler object that handles the event associated with the delegate.

    This parameter provides the fully qualified name of the event handler that handles the particular event that you want a delegate for, combined with the name of the event that the delegate handles.

    For example, the following value creates a delegate for an OnMouseMove event handler implemented in an object named CustomEventHandler:

    &CustomEventHandler::OnMouseMove
    

Return Value

Returns an IXRDelegate<ArgType, [SenderType]> template class that XAML for Windows Embedded has customized for the event handler you specify in T::*pfn. The initial reference count of the object is 0 (zero).

Remarks

This version of the CreateDelegate function creates a reference counted object that is safe to use directly inline with an Add*EventHandler method. For example:

TestEventHandler HandlerObject;
pIButton->AddMouseEnterEventHandler(CreateDelegate(&HandlerObject, &TestEventHandler::OnMouseEnter));

The XAML for Windows Embedded framework and this function work together to properly reference count the delegate object.

When you use this helper function, you can first create a custom object that provides custom event handlers. Then, you can pass an instance of that object into pT.

CreateDelegate creates a delegate template class that represents the event handler that you specified in T::*pfn. Now you can work with this delegate directly, to attach its event handler to an event on a particular object.

To attach the associated event handler to an event on a particular object, you can attach the returned delegate to that object. To do this, use the return value as an input parameter for methods that add delegates to UI objects such as objects derived from IXRFrameworkElement. If you have attached the event handler to a UI object, the UI object will use the delegate to invoke the event handler every time that the object raises the event.

.NET Framework Equivalent

None

Requirements

Header

XRDelegate.h

sysgen

SYSGEN_XAML_RUNTIME

See Also

Reference

CreateDelegate
CreateDelegate(class,class::method,IXRDelegate<ArgType, SenderType>)
XAML for Windows Embedded Functions