次の方法で共有


IXRUIElementCollection (Windows Embedded CE 6.0)

1/6/2010

This class represents a collection of IXRUIElement objects.

Syntax

class IXRUIElementCollection : public IXRCollection<IXRUIElement*, IXRDependencyObject*>

Methods

IXRUIElementCollection inherits the methods from the template class IXRCollection<In_T, Out_T>. It uses In_T parameters of type IXRUIElement* and uses Out_T parameters of type IXRDependencyObject*.

Remarks

IXRUIElementCollection is used by the IXRPanel class to store the IXRUIElement objects that are arranged on a panel object. This collection object is retrieved by IXRPanel::GetChildren.

You can obtain a pointer to this collection by calling IXRPanel::GetChildren. Then, you can use the methods inherited from IXRCollection<In_T, Out_T> to add items, remove items, and also clear the complete collection by calling the inherited method IXRCollection<In_T, Out_T>::Clear.

You can define a UI element collection in Microsoft Silverlight 2 XAML. For information about the differences between XAML in Silverlight for Windows Embedded and Silverlight 2, see Differences Between Silverlight for the Web and Silverlight for Windows Embedded. For more information about how to define this collection in the source XAML for your application, see this Microsoft Web site.

The XAML implicit collection syntax also shows how to populate items in the IXRUIElementCollection by using Silverlight 2 XAML.

Note

Panel.Children is not supported for use as an attached property. For more information about how to define a UI element collection in Silverlight 2 XAML, see this Microsoft Web site.

Example

The following code example shows how to add an IXRUIElement derived object to a canvas in the visual tree by using the IXRUIElementCollection class.

Note

To make the following code example easier to read, security checking and error handling are not included. This code example should not be used in a release configuration unless it has been modified to include them.

#include <windows.h>
#include <XamlRuntime.h>
#include <XRPtr.h>


void AddElementToTree(IXRApplication* pApplication, IXRVisualHost* pVisualHost)
{ 
  IXRButtonPtr greenButton;
  float btnHeight = 6;
  float btnWidth = 12;

  IXRCanvasPtr pCanvas;
  IXRUIElementCollectionPtr pnlChildren;
  int index;

  // Create a new UI element
  pApplication->CreateObject(&greenButton);

  greenButton->SetHeight(btnHeight);
  greenButton->SetWidth(btnWidth);
  greenButton->SetName(L"MyGreenButton");

  // Obtain a pointer to the root of the visual tree
  IXRFrameworkElementPtr pRootElement;
  pVisualHost->GetRootElement(&pRootElement);

  // Traverse the visual tree and find a named canvas object
  pRootElement->FindName(L"MyCanvas", &pCanvas); 

  // Get the collection of elements from the located canvas object
  pCanvas->GetChildren(&pnlChildren);

  // Add the new UI element to the collection
  pnlChildren->Add(greenButton, &index);
}

The previous code example assumes that you have already created an IXRApplication application instance, parsed the XAML into an element tree, and obtained a pointer (pVisualHost) to the visual host. For more information on the programming elements used in this example, see IXRApplication, IXRButton, IXRVisualHost, XRPtr<Interface>, and IXRCanvas.

Inheritance Hierarchy

IXRDependencyObject

    IXRCollection<In_T, Out_T>

        IXRUIElementCollection

.NET Framework Equivalent

System.Windows.Controls.UIElementCollection

Requirements

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

See Also

Reference

Classes for Collection Management