Поделиться через


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

3/28/2014

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

Syntax

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

Methods

Method

Description

IXRDelegate<ArgType, [SenderType]>::Invoke

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

Thread Safety

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.

Remarks

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 :

This object is created internally by 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.

Example

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

Important

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));
  }
}

.NET Framework Equivalent

None.

Requirements

Header

XamlRuntime.h,
XRDelegate.h

sysgen

SYSGEN_XAML_RUNTIME

See Also

Reference

Classes for Application Management