Share via


IXRApplication::CreateHostFromElementTree (Compact 2013)

3/28/2014

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(
  IXRFrameworkElement* 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 XAML for Windows Embedded object.

Remarks

This method assists in integrating a XAML for Windows Embedded 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 the screen by calling ShowWindow.

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 "XRPtr.h"

void CreateNewHost(IXRApplication* pApplication)
{
     IXRGridPtr pRoot;
     IXRButtonPtr pBtn1;
     IXRButtonPtr pBtn2;
     IXRUIElementCollectionPtr pChildCollection;
     IXRVisualHostPtr pVisualHost;
     UINT Index1 = 0;
     UINT Index2 = 1;

     // Create the grid and buttons
     pApplication->CreateObject(&pRoot);
     pApplication->CreateObject(&pBtn1);
     pApplication->CreateObject(&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

See Also

Reference

IXRApplication