Printer Friendly Version      Send     
Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
Silverlight
Grid Class
Other versions are also available for the following:
.NET Framework Class Library for Silverlight
Grid Class
[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

Defines a flexible grid area that consists of columns and rows.

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.

Visual Basic (Declaration)
Public Class Grid _
    Inherits Panel
Visual Basic (Usage)
Dim instance As Grid
C#
public class Grid : Panel
Visual C++
public ref class Grid : public Panel
JScript
public class Grid extends Panel
XAML Object Element Usage
<Grid ...>
  oneOrMoreUIElements
</Grid>
XAML Values
oneOrMoreUIElements

One or more object elements that derive from the UIElement class. Object elements defined here become members of the Children collection.

Columns and rows that are defined within a Grid can take advantage of Star sizing to distribute remaining space proportionally. When Star is selected as the height or width of a row or column, that column or row receives a weighted proportion of the remaining available space. This is in contrast to Auto, which distributes space evenly based on the size of the content that is within a column or row. This value is expressed as * or 2* when you use Extensible Application Markup Language (XAML). In the first case, the row or column would receive one times the available space, while in the second case, the row or column would receive two times the available space, and so on. By combining this technique to proportionally distribute space with a HorizontalAlignment and VerticalAlignment value of Stretch, it is possible to partition layout space by percentage of screen space. Grid is the only layout panel that can distribute space in this manner.

By default, rows and columns take up the least amount of space necessary to accommodate the largest content within any cell contained in a given row or column. For example, if a column has one cell with a long word like "hippopotamus" contained within it but all the other cells in the column have smaller words like "dog", the width of the column will be the width of the largest word (hippopotamus).

You can precisely position child elements of a Grid by using a combination of the Margin property and alignment properties.

Child elements of a Grid are drawn in the order in which they appear in markup or code. As a consequence, layered order (also known as z-order) can be achieved when elements share the same coordinates.

Grid uses the GridLength object to define the sizing characteristics of a RowDefinition or ColumnDefinition. For a definition of each unit type, see GridUnitType.

If a child element is added to a column within a Grid, and the column has its Width property set to Auto, the child will be measured without restrictions. This behavior can prevent horizontal scroll bars from displaying if a ScrollViewer is being used, as the child element is measured as unbounded. For purposes of display, the child is clipped rather than scrolled.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker