Partager via


IXRUIElementCollection (Compact 2013)

3/28/2014

This class represents a collection of IXRUIElement objects.

Syntax

class IXRUIElementCollection : public IXRDependencyObject

Inheritance Hierarchy

IXRDependencyObject

    IXRUIElementCollection

Methods

Method

Description

IXRUIElementCollection::Add

Adds an item to the end of this collection and retrieves the index of where it was added.

IXRUIElementCollection::Clear

Removes all items from this collection.

IXRUIElementCollection::Contains

Determines whether an item is in this collection.

IXRUIElementCollection::GetCount

Retrieves the number of items in this collection.

IXRUIElementCollection::GetItem

Retrieves the item at the specified index in this collection.

IXRUIElementCollection::IndexOf

Searches for the specified item and retrieves the zero-based index of its occurrence within this collection.

IXRUIElementCollection::Insert

Inserts an item into this collection at the location that has the specified index value.

IXRUIElementCollection::Move

Moves an item in this collection from the specified index to the specified position.

IXRUIElementCollection::Remove

Removes a specific item from this collection.

IXRUIElementCollection::RemoveAt

Removes the item at the specified index from this collection.

Thread Safety

Members of this class are thread safe if you previously called IXRApplication::CreateHostFromXaml and supplied it with an XRWindowCreateParams structure that has AllowsMultipleThreadAccess set to true.

Remarks

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

To obtain a pointer to this collection, call IXRPanel::GetChildren. Then, use the methods of this class to add, remove, and also clear the complete collection by calling the IXRUIElementCollection::Clear method.

When you create a class instance, use an IXRUIElementCollectionPtr smart pointer instead of a raw interface pointer. For more information, see XRPtr<Interface>.

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

The XAML implicit collection syntax also shows how to populate items in the IXRUIElementCollection by using Silverlight 3 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 3 XAML, see the UIElementCollection Class on MSDN.

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.

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 AddElementToTree(IXRApplication* pApplication, IXRVisualHost* pVisualHost)
{ 
  IXRButtonPtr greenButton;
  float btnHeight = 6;
  float btnWidth = 12;

  IXRCanvasPtr pCanvas;
  IXRUIElementCollectionPtr pnlChildren;

  // 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, NULL);
}

To use the previous code example, you must 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.

.NET Framework Equivalent

System.Windows.Controls.UIElementCollection

Requirements

Header

XamlRuntime.h

sysgen

SYSGEN_XAML_RUNTIME

See Also

Reference

Classes for Collection Management
IXRPanel::GetChildren