Table of Contents

Class Grid

Namespace
Myra.Graphics2D.UI
Assembly
Myra.dll

A grid widget that displays content in a table layout with support for rows, columns, spanning, and selection.

public class Grid : Container, IItemWithId, INotifyAttachedPropertyChanged, IContainer
Inheritance
Grid
Implements
Inherited Members

Constructors

Grid(Stylesheet, string)

Initializes a new instance of the Grid class with the specified stylesheet and style.

public Grid(Stylesheet stylesheet, string styleName = "")

Parameters

stylesheet Stylesheet

The stylesheet to use for applying the style.

styleName string

The name of the style to apply.

Grid(string)

Initializes a new instance of the Grid class.

public Grid(string styleName = "")

Parameters

styleName string

Fields

ColumnProperty

Attached property that specifies the column index of a child widget within the grid.

public static readonly AttachedPropertyInfo<int> ColumnProperty

Field Value

AttachedPropertyInfo<int>

ColumnSpanProperty

Attached property that specifies the number of columns a child widget spans.

public static readonly AttachedPropertyInfo<int> ColumnSpanProperty

Field Value

AttachedPropertyInfo<int>

RowProperty

Attached property that specifies the row index of a child widget within the grid.

public static readonly AttachedPropertyInfo<int> RowProperty

Field Value

AttachedPropertyInfo<int>

RowSpanProperty

Attached property that specifies the number of rows a child widget spans.

public static readonly AttachedPropertyInfo<int> RowSpanProperty

Field Value

AttachedPropertyInfo<int>

Properties

CanSelectNothing

Gets or sets a value indicating whether nothing can be selected by clicking an already-selected item.

public bool CanSelectNothing { get; set; }

Property Value

bool

CellLocationsX

Gets the X coordinates of each cell's left edge.

[Browsable(false)]
public List<int> CellLocationsX { get; }

Property Value

List<int>

CellLocationsY

Gets the Y coordinates of each cell's top edge.

[Browsable(false)]
public List<int> CellLocationsY { get; }

Property Value

List<int>

ColWidths

Gets the widths of each column in pixels.

[Browsable(false)]
public List<int> ColWidths { get; }

Property Value

List<int>

ColumnSpacing

Gets or sets the spacing in pixels between grid columns.

public int ColumnSpacing { get; set; }

Property Value

int

ColumnsProportions

Gets the collection of column proportions that define how columns divide available space.

[Browsable(false)]
public ObservableCollection<Proportion> ColumnsProportions { get; }

Property Value

ObservableCollection<Proportion>

DefaultColumnProportion

Gets or sets the default proportion used for columns when not explicitly specified.

[Browsable(false)]
public Proportion DefaultColumnProportion { get; set; }

Property Value

Proportion

DefaultRowProportion

Gets or sets the default proportion used for rows when not explicitly specified.

[Browsable(false)]
public Proportion DefaultRowProportion { get; set; }

Property Value

Proportion

GridLinesColor

Gets or sets the color of the grid lines when displayed.

public Color GridLinesColor { get; set; }

Property Value

Color

GridLinesX

Gets the X coordinates of the vertical grid lines.

[Browsable(false)]
public List<int> GridLinesX { get; }

Property Value

List<int>

GridLinesY

Gets the Y coordinates of the horizontal grid lines.

[Browsable(false)]
public List<int> GridLinesY { get; }

Property Value

List<int>

GridSelectionMode

Gets or sets the selection mode for the grid (rows, columns, cells, or none).

public GridSelectionMode GridSelectionMode { get; set; }

Property Value

GridSelectionMode

HoverColumnIndex

Gets or sets the index of the column currently being hovered over, or null if no column is hovered.

[Browsable(false)]
public int? HoverColumnIndex { get; set; }

Property Value

int?

HoverIndexCanBeNull

Gets or sets a value indicating whether the hover index can be null when the mouse is outside the grid.

public bool HoverIndexCanBeNull { get; set; }

Property Value

bool

HoverRowIndex

Gets or sets the index of the row currently being hovered over, or null if no row is hovered.

[Browsable(false)]
public int? HoverRowIndex { get; set; }

Property Value

int?

RowHeights

Gets the heights of each row in pixels.

[Browsable(false)]
public List<int> RowHeights { get; }

Property Value

List<int>

RowSpacing

Gets or sets the spacing in pixels between grid rows.

public int RowSpacing { get; set; }

Property Value

int

RowsProportions

Gets the collection of row proportions that define how rows divide available space.

[Browsable(false)]
public ObservableCollection<Proportion> RowsProportions { get; }

Property Value

ObservableCollection<Proportion>

SelectedColumnIndex

Gets or sets the index of the currently selected column, or null if no column is selected.

[Browsable(false)]
public int? SelectedColumnIndex { get; set; }

Property Value

int?

SelectedRowIndex

Gets or sets the index of the currently selected row, or null if no row is selected.

[Browsable(false)]
public int? SelectedRowIndex { get; set; }

Property Value

int?

SelectionBackground

Gets or sets the brush used to draw the background of selected rows, columns, or cells.

public IBrush SelectionBackground { get; set; }

Property Value

IBrush

SelectionHoverBackground

Gets or sets the brush used to draw the background of rows, columns, or cells being hovered over.

public IBrush SelectionHoverBackground { get; set; }

Property Value

IBrush

ShowGridLines

Gets or sets a value indicating whether grid lines are displayed for debugging purposes.

public bool ShowGridLines { get; set; }

Property Value

bool

Methods

ApplyStyle(WidgetStyle)

Applies the specified widget style to this grid.

protected override void ApplyStyle(WidgetStyle style)

Parameters

style WidgetStyle

The widget style to apply.

CopyFrom(Widget)

Copies the grid properties and column/row proportions from another grid.

protected override void CopyFrom(Widget w)

Parameters

w Widget

The source grid to copy from.

GetCellLocationX(int)

Gets the X coordinate of the cell at the specified column.

public int GetCellLocationX(int col)

Parameters

col int

The column index.

Returns

int

The X coordinate in pixels.

GetCellLocationY(int)

Gets the Y coordinate of the cell at the specified row.

public int GetCellLocationY(int row)

Parameters

row int

The row index.

Returns

int

The Y coordinate in pixels.

GetCellRectangle(int, int)

Gets the bounds rectangle of the cell at the specified column and row.

public Rectangle GetCellRectangle(int col, int row)

Parameters

col int

The column index.

row int

The row index.

Returns

Rectangle

The cell bounds as a rectangle.

GetColumn(Widget)

Gets the column index for the specified widget within the grid.

public static int GetColumn(Widget widget)

Parameters

widget Widget

The widget to query.

Returns

int

The column index.

GetColumnProportion(int)

Gets the proportion for the column at the specified index.

public Proportion GetColumnProportion(int col)

Parameters

col int

The column index.

Returns

Proportion

The column proportion.

GetColumnSpan(Widget)

Gets the column span for the specified widget within the grid.

public static int GetColumnSpan(Widget widget)

Parameters

widget Widget

The widget to query.

Returns

int

The column span value.

GetColumnWidth(int)

Gets the width of the column at the specified index.

public int GetColumnWidth(int index)

Parameters

index int

The column index.

Returns

int

The column width in pixels.

GetRow(Widget)

Gets the row index for the specified widget within the grid.

public static int GetRow(Widget widget)

Parameters

widget Widget

The widget to query.

Returns

int

The row index.

GetRowHeight(int)

Gets the height of the row at the specified index.

public int GetRowHeight(int index)

Parameters

index int

The row index.

Returns

int

The row height in pixels.

GetRowProportion(int)

Gets the proportion for the row at the specified index.

public Proportion GetRowProportion(int row)

Parameters

row int

The row index.

Returns

Proportion

The row proportion, or the default if the index is out of range.

GetRowSpan(Widget)

Gets the row span for the specified widget within the grid.

public static int GetRowSpan(Widget widget)

Parameters

widget Widget

The widget to query.

Returns

int

The row span value.

InternalRender(RenderContext)

Renders the grid content, selection, and grid lines.

public override void InternalRender(RenderContext context)

Parameters

context RenderContext

The render context used for drawing.

InvalidateChildren()

Invalidates the child layout and clears grid-specific state.

protected override void InvalidateChildren()

OnMouseEntered()

Handles the event when the mouse enters the grid.

public override void OnMouseEntered()

OnMouseLeft()

Handles the event when the mouse leaves the grid.

public override void OnMouseLeft()

OnMouseMoved()

Handles the event when the mouse moves within the grid.

public override void OnMouseMoved()

OnTouchDown()

Handles touch down events on the grid, including row/column/cell selection.

public override void OnTouchDown()

SetColumn(Widget, int)

Sets the column index for the specified widget within the grid.

public static void SetColumn(Widget widget, int value)

Parameters

widget Widget

The widget to modify.

value int

The column index to set.

SetColumnSpan(Widget, int)

Sets the column span for the specified widget within the grid.

public static void SetColumnSpan(Widget widget, int value)

Parameters

widget Widget

The widget to modify.

value int

The column span to set.

SetRow(Widget, int)

Sets the row index for the specified widget within the grid.

public static void SetRow(Widget widget, int value)

Parameters

widget Widget

The widget to modify.

value int

The row index to set.

SetRowSpan(Widget, int)

Sets the row span for the specified widget within the grid.

public static void SetRowSpan(Widget widget, int value)

Parameters

widget Widget

The widget to modify.

value int

The row span to set.

Events

HoverIndexChanged

Occurs when the hovered row or column changes.

public event MyraEventHandler HoverIndexChanged

Event Type

MyraEventHandler

SelectedIndexChanged

Occurs when the selected row or column changes.

public event MyraEventHandler SelectedIndexChanged

Event Type

MyraEventHandler