Share via


IXRApplication::RegisterControl (Windows Embedded CE 6.0)

1/6/2010

This method registers a user-defined control that is defined in source XAML with an object tag.

Syntax

virtual HRESULT STDMETHODCALLTYPE RegisterControl(
  REFIID iid,
  const WCHAR* pControlName,
  const WCHAR* pNamespace,
  PFN_CREATE_CONTROL pfCreation,
  UINT* pControlId
) = 0;

Parameters

  • iid
    [in] The interface ID for the control. You can use this IID for creating a control instance when you call IXRApplication::CreateObject.
  • pControlName
    [in] String that specifies the class name of the control that will be defined in the XAML. Use the same name that was defined in the source XAML file. This value differs from the x:Name attribute.
  • pNamespace
    [in] String that specifies the common language runtime (CLR) custom namespace that will be defined in the XAML. Use the same value that was defined in the source XAML file.
  • pfCreation
    [in] PFN_CREATE_CONTROL callback function that specifies the function pointer that is used for creating a control. Silverlight calls this function when it encounters a control name in XAML that is not recognized.
  • pControlId
    [out] Pointer to an integer value that represents the control ID.

Return Value

Returns an HRESULT that indicates success or failure.

Returns XR_E_DUPLICATE_REGISTRATION if an attempt was made to register a custom control with a name that already exists.

Remarks

You can register a custom control that was defined in source XAML so that Silverlight can recognize it when it is parsed into an object.

When you define the custom control in XAML, you must provide the fully-qualified name of the class in the value of the x:Class attribute. It must include both a custom CLR namespace and the control-class name.

The following code example shows the expected syntax for the x:Class attribute in Silverlight:

<object x:Class="CustomNamespace.MyClassname"...>
...
</object>

After you define the control in a XAML definition, you can include it in a XAML graphical-scene implementation. To include it in a graphical implementation, you must provide a XAML CLR namespace declaration and supply the XAML namescope by providing the xmlns prefix declaration with your custom CLR namespace. You must also use "clr-namespace" as a prefix when registering the control. The following example syntax illustrates this:

<RootObject xmlns:CustomNamespace="clr-namespace:MyUINamespace"...>
    <CustomNamespace:MyClassname x:Name="MyCustomControl" .../>
...
</RootObject>

After you define and implement a custom control in XAML, you must provide the C++ application logic to register that control before you parse the source XAML and load it into the visual tree. To do this, call RegisterControl. Notice that the x:Class custom namespace prefix will correspond to the pNamespace parameter, and the x:Class class-name suffix will correspond to the pControlName parameter.

You can use the pControlId value later to register dependency properties or attached properties by calling IXRApplication::RegisterDependencyProperty or IXRApplication::RegisterAttachedProperty.

A registered control can be a C++ class that derives from IXRCustomUserControl. The PFN_CREATE_CONTROL application-defined function returns this C++ class instance to Silverlight. The name of this function is passed to Silverlight during control registration by using IXRApplication::RegisterControl. Elements can be added to this class by using IXRApplication::ParseXamlWithExistingRoot, or by setting the Content property by calling IXRUserControl::SetContent.

.NET Framework Equivalent

None.

Requirements

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

See Also

Reference

IXRApplication