Click or drag to resize
Grid Class
Defines a flexible grid area that consists of columns and rows. Child elements of the Grid are measured and arranged according to their row/column assignments and internal class logic.
Inheritance Hierarchy

Namespace: Windows.UI.Xaml.Controls
Assembly: CSharpXamlForHtml5 (in CSharpXamlForHtml5.dll) Version: 1.0.0.0
Syntax
C#
public class Grid : Panel

The Grid type exposes the following members.

Constructors
  NameDescription
Public methodGrid
Initializes a new instance of the Grid class.
Top
Methods
  NameDescription
Public methodCapturePointer
Sets pointer capture to a UIElement.
(Inherited from UIElement.)
Public methodCreateDomChildWrapper (Overrides UIElementCreateDomChildWrapper(Object, Object).)
Public methodCreateDomElement (Overrides FrameworkElementCreateDomElement(Object, Object).)
Public methodEquals(Object)
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Public methodFindName
Retrieves an object that has the specified identifier name.
(Inherited from FrameworkElement.)
Public methodGetChildsWrapper (Inherited from UIElement.)
Public methodStatic memberGetColumn
Gets the value of the Grid.Column XAML attached property from the specified FrameworkElement.
Public methodGetDomElementWhereToPlaceChild (Overrides UIElementGetDomElementWhereToPlaceChild(UIElement).)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodStatic memberGetRow
Gets the value of the Grid.Row XAML attached property from the specified FrameworkElement.
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodGetValue
Returns the current effective value of a dependency property from a DependencyObject.
(Inherited from DependencyObject.)
Public methodGetVisualStateValue (Inherited from DependencyObject.)
Protected methodINTERNAL_OnDetachedFromVisualTree (Overrides DependencyObject.INTERNAL_OnDetachedFromVisualTree.)
Protected methodManageIsEnabled (Inherited from FrameworkElement.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Protected methodOnAfterApplyHorizontalAlignmentAndWidth (Inherited from FrameworkElement.)
Protected methodOnAfterApplyVerticalAlignmentAndWidth (Inherited from FrameworkElement.)
Public methodOnApplyTemplate
Invoked whenever application code or internal processes (such as a rebuilding layout pass) call ApplyTemplate. In simplest terms, this means the method is called just before a UI element displays in your app. Override this method to influence the default post-template logic of a class.
(Inherited from FrameworkElement.)
Protected methodOnGotFocus
Raises the GotFocus event
(Inherited from UIElement.)
Protected methodOnKeyDown
Raises the KeyDown event
(Inherited from UIElement.)
Protected methodOnKeyUp
Raises the KeyUp event
(Inherited from UIElement.)
Protected methodOnLostFocus
Raises the LostFocus event
(Inherited from UIElement.)
Protected methodOnPointerEntered
Raises the PointerEntered event
(Inherited from UIElement.)
Protected methodOnPointerExited
Raises the PointerExited event
(Inherited from UIElement.)
Protected methodOnPointerMoved (Inherited from UIElement.)
Protected methodOnPointerPressed
Raises the PointerPressed event
(Inherited from UIElement.)
Protected methodOnPointerReleased
Raises the PointerReleased event
(Inherited from UIElement.)
Protected methodOnTapped
Raises the Tapped event
(Inherited from UIElement.)
Public methodReadLocalValue
Returns the local value of a dependency property, if a local value is set.
(Inherited from DependencyObject.)
Public methodReleasePointerCapture
Releases pointer captures for capture of one specific pointer by this UIElement.
(Inherited from UIElement.)
Public methodSetBinding
Attaches a binding to a FrameworkElement, using the provided binding object.
(Inherited from DependencyObject.)
Public methodStatic memberSetColumn
Sets the value of the Grid.Column XAML attached property on the specified FrameworkElement.
Public methodSetInheritedValue
Sets the inherited value of a dependency property on a DependencyObject. Do not use this method.
(Inherited from DependencyObject.)
Public methodSetLocalValue
Sets the local value of a dependency property on a DependencyObject while not overriding a hypothetical Binding (example: when the user writes in a TextBox with a two way Binding on its Text property).
(Inherited from DependencyObject.)
Public methodStatic memberSetRow
Sets the value of the Grid.Row XAML attached property on the specified FrameworkElement.
Public methodSetValue
Sets the local value of a dependency property on a DependencyObject.
(Inherited from DependencyObject.)
Public methodSetVisualStateValue (Inherited from DependencyObject.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Public methodTransformToVisual
Returns a transform object that can be used to transform coordinates from the UIElement to the specified object.
(Inherited from UIElement.)
Top
Fields
  NameDescription
Public fieldStatic memberColumnDefinitionsProperty
Identifies the ColumnDefinitions dependency property.
Public fieldStatic memberColumnProperty
Identifies the Grid.Column XAML attached property
Public fieldStatic memberRowDefinitionsProperty
Identifies the RowDefinitions dependency property.
Public fieldStatic memberRowProperty
Identifies the Grid.Row XAML attached property.
Top
Properties
  NameDescription
Public propertyActualHeight
Gets the rendered height of a FrameworkElement. The FrameworkElement must be in the visual tree, otherwise this property will return double.NaN.
(Inherited from FrameworkElement.)
Public propertyActualWidth
Gets the rendered width of a FrameworkElement. The FrameworkElement must be in the visual tree, otherwise this property will return double.NaN.
(Inherited from FrameworkElement.)
Public propertyBackground
Gets or sets a Brush that is used to fill the panel.
(Inherited from Panel.)
Public propertyChildren
Gets the collection of child elements of the panel.
(Inherited from Panel.)
Public propertyColumnDefinitions
Gets a list of ColumnDefinition objects defined on this instance of Grid.
Public propertyCursor
Gets or sets the cursor that displays when the mouse pointer is over this element.
(Inherited from FrameworkElement.)
Public propertyDataContext
Gets or sets the data context for a FrameworkElement when it participates in data binding.
(Inherited from FrameworkElement.)
Public propertyDispatcher
Gets the CoreDispatcher that this object is associated with.
(Inherited from DependencyObject.)
Public propertyEffect (Inherited from UIElement.)
Public propertyHeight
Gets or sets the suggested height of a FrameworkElement.
(Inherited from FrameworkElement.)
Public propertyHorizontalAlignment
Gets or sets the horizontal alignment characteristics that are applied to a FrameworkElement when it is composed in a layout parent, such as a panel or items control.
(Inherited from FrameworkElement.)
Public propertyIsEnabled
Gets or sets a value indicating whether the user can interact with the control.
(Inherited from FrameworkElement.)
Public propertyIsHitTestVisible
Gets or sets whether the contained area of this UIElement can return true values for hit testing.
(Inherited from FrameworkElement.)
Public propertyIsLoaded
Gets a value that indicates whether this element is in the Visual Tree, that is, if it has been loaded for presentation.
(Inherited from FrameworkElement.)
Public propertyMargin
Gets or sets the outer margin of a FrameworkElement.
(Inherited from FrameworkElement.)
Public propertyName
Gets or sets the identifying name of the object. When a XAML processor creates the object tree from XAML markup, run-time code can refer to the XAML-declared object by this name.
(Inherited from FrameworkElement.)
Public propertyOpacity
Gets or sets the degree of the object's opacity. A value between 0 and 1.0 that declares the opacity factor, with 1.0 meaning full opacity and 0 meaning transparent. The default value is 1.0.
(Inherited from UIElement.)
Public propertyRenderTransform
Gets or sets transform information that affects the rendering position of a UIElement.
(Inherited from UIElement.)
Public propertyRenderTransformOrigin (Inherited from UIElement.)
Public propertyResources
Gets the locally defined resource dictionary. In XAML, you can establish resource items as child object elements of a frameworkElement.Resources property element, through XAML implicit collection syntax.
(Inherited from FrameworkElement.)
Public propertyRowDefinitions
Gets a list of RowDefinition objects defined on this instance of Grid.
Public propertyStyle
Gets or sets an instance Style that is applied for this object during rendering.
(Inherited from FrameworkElement.)
Public propertyTag
Gets or sets an arbitrary object value that can be used to store custom information about this object.
(Inherited from FrameworkElement.)
Public propertyUseLayoutRounding
Gets or sets a value that determines whether rendering for the object and its visual subtree should use rounding behavior that aligns rendering to whole pixels.
(Inherited from UIElement.)
Public propertyVerticalAlignment
Gets or sets the vertical alignment characteristics that are applied to a FrameworkElement when it is composed in a parent object such as a panel or items control.
(Inherited from FrameworkElement.)
Public propertyVisibility
Gets or sets the visibility of a UIElement. A UIElement that is not visible is not rendered and does not communicate its desired size to layout.
(Inherited from UIElement.)
Public propertyWidth
Gets or sets the width of a FrameworkElement.
(Inherited from FrameworkElement.)
Top
Events
  NameDescription
Public eventGotFocus
Occurs when the pointer device that previously initiated a Press action is pressed, while within this element. Note that ONLY sender's informations are currently filled (not pointer's)
(Inherited from UIElement.)
Public eventKeyDown
Occurs when a keyboard key is pressed while the UIElement has focus.
(Inherited from UIElement.)
Public eventKeyUp
Occurs when a keyboard key is released while the UIElement has focus.
(Inherited from UIElement.)
Public eventLoaded
Occurs when a FrameworkElement has been constructed and added to the object tree.
(Inherited from FrameworkElement.)
Public eventLostFocus
Occurs when a UIElement loses focus.
(Inherited from UIElement.)
Public eventPointerEntered
Occurs when a pointer enters the hit test area of this element.
(Inherited from UIElement.)
Public eventPointerExited
Occurs when a pointer leaves the hit test area of this element.
(Inherited from UIElement.)
Public eventPointerMoved
Occurs when the pointer device that previously initiated a Press action is moved, while within this element.
(Inherited from UIElement.)
Public eventPointerPressed
Occurs when the pointer device that previously initiated a Press action is pressed, while within this element.
(Inherited from UIElement.)
Public eventPointerReleased
Occurs when the pointer device that previously initiated a Press action is released, while within this element.
(Inherited from UIElement.)
Public eventTapped
Occurs when an otherwise unhandled Tap interaction occurs over the hit test area of this element.
(Inherited from UIElement.)
Public eventUnloaded
Occurs when this object is no longer connected to the main object tree.
(Inherited from FrameworkElement.)
Top
Examples
You can add a Grid with two rows and columns to the XAML as follows:
XAML
<Grid Width="300" Height="200" Background="Blue" HorizontalAlignment="Left">
    <Grid.RowDefinitions>
        <RowDefinition Height="40" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="70" />
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>
        <!--Children here.-->
    </Grid>
Or in C#:
C#
Grid myGrid = new Grid();
myGrid.Width = 300;
myGrid.Height = 200;
myGrid.Background = new SolidColorBrush(Windows.UI.Colors.Blue);
myGrid.HorizontalAlignment = HorizontalAlignment.Left;

//We create and add the rows and columns:
//First column:
ColumnDefinition columnDefinition = new ColumnDefinition();
columnDefinition.Width = new GridLength(70, GridUnitType.Pixel);
myGrid.ColumnDefinitions.Add(columnDefinition);
//Second column:
ColumnDefinition columnDefinition2 = new ColumnDefinition();
columnDefinition2.Width = new GridLength(1, GridUnitType.Star);
myGrid.ColumnDefinitions.Add(columnDefinition2);

//First row:
RowDefinition rowDefinition = new RowDefinition();
rowDefinition.Height = new GridLength(40, GridUnitType.Pixel);
myGrid.RowDefinitions.Add(rowDefinition);
//Second Row:
RowDefinition rowDefinition2 = new RowDefinition();
rowDefinition2.Height = new GridLength(1, GridUnitType.Star);
myGrid.RowDefinitions.Add(rowDefinition2);

//Do not forget to add the Grid to the visual tree.
See Also