IXRGrid (Windows Embedded CE 6.0)

1/6/2010

This class represents a flexible-grid surface that consists of columns and rows.

Syntax

class IXRGrid : public IXRPanel

Methods

Method Description

IXRGrid::GetColumnDefinitions

Retrieves a collection of column definitions that are defined on this instance of IXRGrid.

IXRGrid::GetRowDefinitions

Retrieves a collection of row definitions that are defined on this instance of IXRGrid.

IXRGrid::GetShowGridLines

Retrieves a value that indicates whether gridlines are visible inside this grid object.

IXRGrid::SetShowGridLines

Sets a value that indicates whether gridlines are visible inside this grid object.

Remarks

A grid is the most flexible and powerful container object provided by Silverlight.

After you create a grid object by using the IXRGrid class, you can position an object in a specific cell of that grid in C++, by referencing the grid row and the grid column for the object position directly on that object by setting the Grid.Column and Grid.Row attached properties on the child object. For more information, see IXRDependencyObject::SetAttachedProperty.

By default, a grid contains one row and one column. To define multiple rows and columns, you can add to the collection of column definitions or to the collection of row definitions. To retrieve these collections, call IXRGrid::GetColumnDefinitions or IXRGrid::GetRowDefinitions. Each IXRRowDefinition and IXRColumnDefinition object inside these collections defines a single row or column. The IXRRowDefinition and IXRColumnDefinition objects also define the size of each row and column, by using the XRGridLength structure. For a definition of each unit type, see XRGridUnitType.

Content can span across multiple rows and columns by using the Grid.RowSpan and Grid.ColumnSpan attached properties in Silverlight 2 XAML. You can set these attached properties by using the inherited method IXRDependencyObject::SetAttachedProperty.

The Margin property of an IXRFrameworkElement derived object describes the distance between an element and its child or peer elements. The HorizontalAlignment and VerticalAlignment properties describe how a child element should be positioned inside the allocated layout space of a parent element. You can precisely position child elements of a grid object by using a combination of the inherited methods IXRFrameworkElement::SetMargin, IXRFrameworkElement::SetHorizontalAlignment, and IXRFrameworkElement::SetVerticalAlignment.

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

Example

The following code example shows how to create a grid object and its rows and columns, set attached properties to UI elements in order to add them to the grid, and add the grid to the content of an item in the element tree.

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 CreateGrid(IXRGrid** pGrid, IXRApplication *pApplicationObject, IXRVisualHost* pVisualHost, int nrow, int ncol, IXRButton* pGreenButton)
{
IXRColumnDefinitionCollectionPtr pColDefCollection;
IXRRowDefinitionCollectionPtr    pRowDefCollection;

IXRColumnDefinitionPtr           pColumn;
IXRRowDefinitionPtr              pRow;

int i=0;

// Create a new grid object from the IXRApplication.
//
pApplicationObject->CreateObject(IID_IXRGrid, &pGrid);

// Set the properties you want on the grid
// (for example, columns, rows, name, gridlines, etc.).
// 

(*pGrid)->SetShowGridLines(false);

      (*pGrid)->SetName(L"ExampleGrid");

      (*pGrid)->GetColumnDefinitions(&pColDefCollection);

      (*pGrid)->GetRowDefinitions(&pRowDefCollection);
 

// Create columns per the number of columns specified in ncol.
//
for (i=0; i<ncol; i++) 

      {

            pApplicationObject->CreateObject(IID_IXRColumnDefinition, (IXRDependencyObject**)&pColumn);

            pColDefCollection->Add(pColumn, NULL);

      }

 

// Create rows per the number of rows specified in nrow.
//

      for (i=0; i<nrow; i++) 

      {

            pApplicationObject->CreateObject(IID_IXRRowDefinition, &pRow);

            pRowDefCollection->Add(pRow, NULL);
     }
    // Position an existing green-button object in the first row in the 
    // first column of the grid.
    //
    pGreenButton->SetAttachedProperty(L"Grid.Row", 0);
    pGreenButton->SetAttachedProperty(L"Grid.Column", 0);

    // Now get the root element (as a user control) from your visual 
    // host.
IXRFrameworkElementPtr pRootElement;
    pVisualHost->GetRootElement(&pRootElement);

    // Find the IXRUserControl object named "MyUserControl".
IXRUserControlPtr pUserControl;
    pRootElement->FindName(L"MyUserControl", &pUserControl);

    // Now add our new grid as the content of the user control.
    //
    pUserControl->SetContent(&pGrid);

}

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

Inheritance Hierarchy

IXRDependencyObject

    IXRUIElement

        IXRFrameworkElement

            IXRPanel

                IXRGrid

.NET Framework Equivalent

System.Windows.Controls.Grid

Requirements

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

See Also

Reference

Classes for UI Element Management

Other Resources