Class Grid
Defines a flexible grid area that consists of columns and rows.
[ControlCategory("Containers")]
public class Grid : ContainerControl, IBaseObject, IDisposableObject, ISupportInitialize, IFocusable, ITextProperty, IComponent, IControl, IDisposable, IWin32Window, INotifyDataErrorInfo
- Inheritance
-
Grid
- Implements
Examples
Here is how to declare a Grid in UIXML:
<Grid Name="grid" Margin="16,16,16,246">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Label Grid.ColumnSpan="3" Grid.Row="0" Text="2021 Products Shipped"/>
<Label Grid.Row="1" Grid.Column="0" Text="Quarter 1"/>
<Label Grid.Row="1" Grid.Column="1" Text="Quarter 2"/>
<Label Grid.Row="1" Grid.Column="2" Text="Quarter 3"/>
<Label Grid.Row="2" Grid.Column="0" Text="50000"/>
<Label Grid.Row="2" Grid.Column="1" Text="100000"/>
<Label Grid.Row="2" Grid.Column="2" Text="150000"/>
<Label Grid.ColumnSpan="3" Grid.Row="3" Text="Total Units: 300000"/>
</Grid>
And the corresponding event handler in the code-behind:
Also, a Grid can be created from code:
var Grid = new Alternet.UI.Grid();
Grid.RowDefinitions.Add(new Alternet.UI.RowDefinition { Height = new Alternet.UI.GridLength(1, Alternet.UI.GridUnitType.Star) });
Grid.RowDefinitions.Add(new Alternet.UI.RowDefinition { Height = new Alternet.UI.GridLength(1, Alternet.UI.GridUnitType.Auto) });
var bt1 = new Button { Text = "First button" };
var bt2 = new Button { Text = "Second button" };
Grid.Children.Add(bt1);
Grid.Children.Add(bt2);
Alternet.UI.Grid.SetRow(bt1, 0);
Alternet.UI.Grid.SetRow(bt2, 1);
Remarks
A Grid contains a collection of Control objects, which are in the Children property.
Child controls of a Grid are drawn in the order in which they appear in UIXML or code. As a consequence, layered order (also known as z-order) can be achieved when controls share the same coordinates.
Child controls of a Grid can be absolutely positioned relative to the upper-left corner of their "cell" boundaries.
Examples of how a Grid can look on different platforms:
Constructors
Properties
- ColumnCount
Gets or sets count of ColumnDefinitions.
- ColumnDefinitions
Gets a GridColumnCollection defined on this instance of Grid.
- ControlKind
Returns control identifier.
- RowCount
Gets or sets count of RowDefinitions.
- RowDefinitions
Gets a GridRowCollection defined on this instance of Grid.
Methods
- AddAutoColumn()
Adds ColumnDefinition instance with Width equal to Auto.
- AddAutoRow()
Adds RowDefinition instance with Height equal to Auto.
- AddStarColumn()
Adds ColumnDefinition instance with Width equal to Star.
- AddStarRow()
Adds RowDefinition instance with Height equal to Star.
- GetColumn(Control)
Gets a value that indicates which column child control within a Grid should appear in.
- GetColumnSpan(Control)
Gets a value that indicates the total number of columns that child content spans within a Grid.
- GetPreferredSize(SizeD)
Retrieves the size of a rectangular area into which a control can be fitted, in device-independent units.
- GetRow(Control)
Gets a value that indicates which row child control within a Grid should appear in.
- GetRowSpan(Control)
Gets a value that indicates the total number of rows that child content spans within a Grid.
- OnCellChanged(EventArgs)
Called when the CellChanged event is raised.
- OnChildRemoved(Control)
Called when a Control is removed from the Children collections.
- OnLayout()
Called when the control should reposition its child controls.
- OnPaint(PaintEventArgs)
Called when the control is redrawn. See Paint for details.
- SetColumn(Control, int)
Sets a value that indicates which column child control within a Grid should appear in.
- SetColumnSpan(Control, int)
Sets a value that indicates the total number of columns that child content spans within a Grid.
- SetRow(Control, int)
Sets a value that indicates which row child control within a Grid should appear in.
- SetRowColumn(Control, int, int)
Sets a value that indicates which row and column child control within a Grid should appear in.
- SetRowSpan(Control, int)
Sets a value that indicates the total number of rows that child content spans within a Grid.
- Setup(Control[,])
Initializes Grid rows and columns for the specified controls.