Table of Contents

Class Grid

Namespace
Avalonia.Controls
Assembly
Avalonia.Controls.dll

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

public class Grid : Panel, INotifyPropertyChanged, IDataContextProvider, ILogical, IThemeVariantHost, IResourceHost, IResourceNode, IStyleHost, ISetLogicalParent, ISetInheritanceParent, ISupportInitialize, IStyleable, INamed, IInputElement, IDataTemplateHost, ISetterValue, IChildIndexProvider
Inheritance
Grid
Implements
Inherited Members
Extension Methods

Constructors

Grid()

Default constructor.

public Grid()

Fields

ColumnProperty

Column property. This is an attached property. Grid defines Column property, so that it can be set on any element treated as a cell. Column property specifies child's position with respect to columns.

public static readonly AttachedProperty<int> ColumnProperty

Field Value

AttachedProperty<int>

Remarks

Columns are 0 - based. In order to appear in first column, element should have Column property set to 0.

Default value for the property is 0.

ColumnSpacingProperty

Defines the ColumnSpacing property.

public static readonly StyledProperty<double> ColumnSpacingProperty

Field Value

StyledProperty<double>

ColumnSpanProperty

ColumnSpan property. This is an attached property. Grid defines ColumnSpan, so that it can be set on any element treated as a cell. ColumnSpan property specifies child's width with respect to columns. Example, ColumnSpan == 2 means that child will span across two columns.

public static readonly AttachedProperty<int> ColumnSpanProperty

Field Value

AttachedProperty<int>

Remarks

Default value for the property is 1.

IsSharedSizeScopeProperty

IsSharedSizeScope property marks scoping element for shared size.

public static readonly AttachedProperty<bool> IsSharedSizeScopeProperty

Field Value

AttachedProperty<bool>

RowProperty

Row property. This is an attached property. Grid defines Row, so that it can be set on any element treated as a cell. Row property specifies child's position with respect to rows.

Rows are 0 - based. In order to appear in first row, element should have Row property set to 0.

Default value for the property is 0.

public static readonly AttachedProperty<int> RowProperty

Field Value

AttachedProperty<int>

RowSpacingProperty

Defines the RowSpacing property.

public static readonly StyledProperty<double> RowSpacingProperty

Field Value

StyledProperty<double>

RowSpanProperty

RowSpan property. This is an attached property. Grid defines RowSpan, so that it can be set on any element treated as a cell. RowSpan property specifies child's height with respect to row grid lines. Example, RowSpan == 3 means that child will span across three rows.

public static readonly AttachedProperty<int> RowSpanProperty

Field Value

AttachedProperty<int>

Remarks

Default value for the property is 1.

ShowGridLinesProperty

ShowGridLines property. This property is used mostly for simplification of visual debugging. When it is set to true grid lines are drawn to visualize location of grid lines.

public static readonly StyledProperty<bool> ShowGridLinesProperty

Field Value

StyledProperty<bool>

Properties

ColumnDefinitions

Returns a ColumnDefinitions of column definitions.

public ColumnDefinitions ColumnDefinitions { get; set; }

Property Value

ColumnDefinitions

ColumnSpacing

Gets or sets the size of the spacing to place between grid columns.

public double ColumnSpacing { get; set; }

Property Value

double

RowDefinitions

Returns a RowDefinitions of row definitions.

public RowDefinitions RowDefinitions { get; set; }

Property Value

RowDefinitions

RowSpacing

Gets or sets the size of the spacing to place between grid rows.

public double RowSpacing { get; set; }

Property Value

double

ShowGridLines

ShowGridLines property.

public bool ShowGridLines { get; set; }

Property Value

bool

Methods

ArrangeOverride(Size)

Content arrangement.

protected override Size ArrangeOverride(Size arrangeSize)

Parameters

arrangeSize Size

Arrange size

Returns

Size

ChildrenChanged(object?, NotifyCollectionChangedEventArgs)

protected override void ChildrenChanged(object? sender, NotifyCollectionChangedEventArgs e)

Parameters

sender object
e NotifyCollectionChangedEventArgs

GetColumn(Control)

Helper for reading Column property from a Control.

public static int GetColumn(Control element)

Parameters

element Control

Control to read Column property from.

Returns

int

Column property value.

GetColumnSpan(Control)

Helper for reading ColumnSpan property from a Control.

public static int GetColumnSpan(Control element)

Parameters

element Control

Control to read ColumnSpan property from.

Returns

int

ColumnSpan property value.

GetIsSharedSizeScope(Control)

Helper for reading IsSharedSizeScope property from a Control.

public static bool GetIsSharedSizeScope(Control element)

Parameters

element Control

Control to read IsSharedSizeScope property from.

Returns

bool

IsSharedSizeScope property value.

GetRow(Control)

Helper for reading Row property from a Control.

public static int GetRow(Control element)

Parameters

element Control

Control to read Row property from.

Returns

int

Row property value.

GetRowSpan(Control)

Helper for reading RowSpan property from a Control.

public static int GetRowSpan(Control element)

Parameters

element Control

Control to read RowSpan property from.

Returns

int

RowSpan property value.

MeasureOverride(Size)

Content measurement.

protected override Size MeasureOverride(Size constraint)

Parameters

constraint Size

Constraint

Returns

Size

Desired size

SetColumn(Control, int)

Helper for setting Column property on a Control.

public static void SetColumn(Control element, int value)

Parameters

element Control

Control to set Column property on.

value int

Column property value.

SetColumnSpan(Control, int)

Helper for setting ColumnSpan property on a Control.

public static void SetColumnSpan(Control element, int value)

Parameters

element Control

Control to set ColumnSpan property on.

value int

ColumnSpan property value.

SetIsSharedSizeScope(Control, bool)

Helper for setting IsSharedSizeScope property on a Control.

public static void SetIsSharedSizeScope(Control element, bool value)

Parameters

element Control

Control to set IsSharedSizeScope property on.

value bool

IsSharedSizeScope property value.

SetRow(Control, int)

Helper for setting Row property on a Control.

public static void SetRow(Control element, int value)

Parameters

element Control

Control to set Row property on.

value int

Row property value.

SetRowSpan(Control, int)

Helper for setting RowSpan property on a Control.

public static void SetRowSpan(Control element, int value)

Parameters

element Control

Control to set RowSpan property on.

value int

RowSpan property value.