IXRApplication::RegisterControl (Compact 2013)

3/28/2014

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

Syntax

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

Parameters

  • iid
    [in] The interface ID (IID) for the control. You can use this IID to create 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 to create a control. XAML for Windows Embedded calls this function when it encounters a control name in XAML that is not recognized.
  • pObjectId
    [out] Pointer to an integer value that represents the control ID.

Return Value

An HRESULT returns S_OK if successful; otherwise returns a non-zero error code. Possible return values include the following.

Value

Description

S_OK

Success.

XR_E_DUPLICATE_REGISTRATION

You attempted 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 XAML for Windows Embedded 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 XAML for Windows Embedded:

<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. Note 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 pObjectId 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 XAML for Windows Embedded. The name of this function is passed to XAML for Windows Embedded 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

See Also

Reference

IXRApplication