Share via


XRCustomUserControlImpl<Base,IFace> (Windows Embedded CE 6.0)

1/6/2010

This class implements the IXRCustomUserControl interface and is the base class for classes implementing custom user controls.

Syntax

template<typename Base,typename IFace = IXRCustomUserControl>
class XRCustomUserControlImpl : public XRControlThunk<IFace>

Parameters

Template Parameter Description

Base

Base class that implements the IFace interface. Inherits from XRCustomUserControlImpl.

IFace

Optional. Custom user control interface that inherits from IXRCustomUserControl.

Methods

Method Description

XRCustomUserControlImpl::OnLoaded

Allows you to attach delegates to elements in the newly created visual tree. It is the last step in preparing a custom user control for use.

XRCustomUserControlImpl::Register

Registers the custom user control with Silverlight.

Remarks

This class implements IUnknown and provides wrapper implementations of the methods in IXRCustomUserControl. This includes the methods that IXRCustomUserControl inherits from the following classes:

IXRDependencyObject

These wrapper methods pass any call to the corresponding method in the Derived class, as shown in the following example.

        virtual HRESULT STDMETHODCALLTYPE HitTest(
  __in XRRect *pRect,
  __out IXRHitTestResults** ppElements
  )
  {  // m_pCustomUserControlBase points to the Derived class.
    if (m_pCustomUserControlBase == NULL)
    {
      return E_FAIL;
    }
    return m_pCustomUserControlBase->HitTest(pRect, ppElements);
  }

Example

The following code example declares both a custom user control interface and an implementation class based on the XRCustomUserControlImpl class.

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.

// Define a GUID for the new interface.
DEFINE_XR_IID(IMyCustomControl, "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");

// Create the interface with any custom methods needed.
class IMyCustomControl: public IXRCustomUserControl
{
public:
    virtual HRESULT DoSomething() = 0;
};

// Create the implementing class 
class __declspec(uuid("{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}"))
  MyCustomControl:public XRCustomUserControlImpl<
    MyCustomControl, 
    IMyCustomControl
    >
{
Public:
  // Override XRCustomUserControlImpl::OnLoaded
  // to get child objects and set up delegates
  HRESULT OnLoaded(__in IXRDependencyObject *pRoot);

  static HRESULT GetXamlSource(__in XRXamlSource* pXamlSource)
  {
    pXamlSource->SetResource(
      g_hInstance,
      RT_XAML,
      MAKEINTRESOURCE(ID_MYCUSTOMCONTROL_XAML
      ));
    return S_OK;
  }

  static HRESULT Register()
  {
    return XRCustomUserControlImpl::Register(
      __uuidof(MyCustomControl),
      L"MyCustomControl",
      L"clr-namespace:MyCustomNamespace"
      );

    //Register any dependency properties.
  }

HRESULT DoSomething()
  {
    // Do something here.
  }
};

.NET Framework Equivalent

None.

Requirements

Header xrcustomcontrol.h
sysgen SYSGEN_XAML_RUNTIME
Windows Embedded CE Windows Embedded CE 6.0 R3

See Also

Reference

Classes for UI Element Management

Concepts

Create a Custom User Control in Silverlight for Windows Embedded