IXRDelegate<ArgType, [SenderType]> (Compact 7)

3/12/2014

This C++ template class represents a delegate object customized for a specific type of event.


template <typename ArgType, typename SenderType = IXRDependencyObject>
class __declspec(novtable) IXRDelegate : public IUnknown

Method Description

IXRDelegate<ArgType, [SenderType]>::Invoke

Causes a delegate object to call the event handler that is represented by the delegate object.

Members of this class are thread safe if you previously called IXRApplication::CreateHostFromXaml and supplied it with an XRWindowCreateParams structure that has AllowsMultipleThreadAccess set to true.

This template class provides the basic structure of a generic delegate object. You can customize it by specifying a structure for the generic ArgType parameter that stores data for a specific event type. When you use it for custom events, you can also customize it by specifying the object sender in the optional SenderType parameter.

The following list shows the structures that hold data for the event types supported by Microsoft Silverlight for Windows Embedded:

This object is created internally by Silverlight for Windows Embedded when an application calls the helper function CreateDelegate. This helper function takes an object and a method pointer (to an event handler) and converts them both into an IXRDelegate<ArgType, [SenderType]> object.

This class also supports the methods on the IUnknown interface. The inherited method IUnknown::QueryInterface succeeds only after the IXRDelegate<ArgType, [SenderType]> object is created by using CreateDelegate.

The following example code creates a delegate by using the IXRUIElement::AddMouseEnterEventHandler method.

Ee503295.note(en-us,WinEmbedded.70).gifImportant:
For readability, the following code example does not contain security checking or error handling. Do not use the following code in a production environment.
#include <windows.h>
#include <XamlRuntime.h>
#include <XRDelegate.h>
#include <XRPtr.h>

void AddEventHandler(IXRVisualHost* pVisualHost, CustomObject* pObject)
{
  IXRButtonPtr pButton;
  IXRFrameworkElementPtr pRootElement;

  pVisualHost->GetRootElement(&pRootElement);
  pRootElement->FindName(L"Button1", &pButton);
  if (pButton)
  {
      pButton->AddMouseEnterEventHandler(CreateDelegate(&pObject, &CustomObject::OnMouseEnter));
  }
}

Header

XamlRuntime.h,
XRDelegate.h

sysgen

SYSGEN_XAML_RUNTIME

Show: