Partager via


IXRApplication::CreateHostFromElementTree (Windows Embedded CE 6.0)

1/6/2010

This method creates a visual host that hosts an existing element tree so that the code in the application instance can access or modify the elements in that tree.

Syntax

 virtual HRESULT STDMETHODCALLTYPE CreateHostFromElementTree(
    IXRUIElement* pElementTree,
    XRWindowCreateParams*   pCreateParams,
    IXRVisualHost** ppHost
) = 0;

Parameters

  • pCreateParams
    [in] Pointer to an XRWindowCreateParams object that contains parameters which are used to create the host window. This parameter is optional.
  • ppHost
    [out] Pointer to an IXRVisualHost object that represents the newly created visual host.

Return Value

Returns an HRESULT that indicates success or failure.

Returns XR_E_INVALID_ROOT_FOR_CREATING_HOST when an invalid root is passed into pElementTree to create a host. An invalid root can be a child element or a root that already belongs to a valid graphical scene. Notice that the root object cannot have a parent object.

Returns XR_E_INVALID_OBJECT if pElementTree is not a Silverlight object.

Remarks

This method assists in integrating a Silverlight application together with the UI controls and UI resources defined in XAML.

If you want to create a visual host and also create an element tree by parsing a XAML file, call IXRApplication::CreateHostFromXaml instead of this method.

If you want to create an element tree only, call IXRApplication::ParseXaml instead of this method.

Example

The following code example creates a new branch of the object tree that consists of a grid and two buttons. Then, it generates a visual host to host the new tree branch and displays it on screen by calling ShowWindow.

#include "stdafx.h"
#include "XamlRuntime.h"

CreateNewHost(IXRApplication* pApplication)
{
IXRGrid* pRoot;
IXRButton* pBtn1;
IXRButton* pBtn2;
IXRUIElementCollection* pChildCollection;
IXRVisualHost* pVisualHost;
UINT Index1 = 0;
UINT Index2 = 1;

// Create the grid and buttons
CreateObject(IID_IXRGrid, &pRoot);
CreateObject(IID_IXRButton, &pBtn1);
CreateObject(IID_IXRButton, &pBtn2);

// Add the buttons to the grid's collection
pRoot->GetChildren(&pChildCollection);

pChildCollection->Insert(Index1, &pBtn1);
pChildCollection->Insert(Index2, &pBtn2);

// Create a visual host and show its window
pApplication->CreateHostFromElementTree(&pRoot, NULL, &pVisualHost);

pVisualHost->ShowWindow();
}

The previous code example assumes that an application instance was already created. For more information about the classes used in this example, see IXRApplication, IXRGrid, IXRButton, IXRUIElementCollection, and IXRVisualHost.

.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