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
stylesheetStylesheetThe stylesheet to use for applying the style.
styleNamestringThe name of the style to apply.
Grid(string)
Initializes a new instance of the Grid class.
public Grid(string styleName = "")
Parameters
styleNamestring
Fields
ColumnProperty
Attached property that specifies the column index of a child widget within the grid.
public static readonly AttachedPropertyInfo<int> ColumnProperty
Field Value
ColumnSpanProperty
Attached property that specifies the number of columns a child widget spans.
public static readonly AttachedPropertyInfo<int> ColumnSpanProperty
Field Value
RowProperty
Attached property that specifies the row index of a child widget within the grid.
public static readonly AttachedPropertyInfo<int> RowProperty
Field Value
RowSpanProperty
Attached property that specifies the number of rows a child widget spans.
public static readonly AttachedPropertyInfo<int> RowSpanProperty
Field Value
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
CellLocationsX
Gets the X coordinates of each cell's left edge.
[Browsable(false)]
public List<int> CellLocationsX { get; }
Property Value
CellLocationsY
Gets the Y coordinates of each cell's top edge.
[Browsable(false)]
public List<int> CellLocationsY { get; }
Property Value
ColWidths
Gets the widths of each column in pixels.
[Browsable(false)]
public List<int> ColWidths { get; }
Property Value
ColumnSpacing
Gets or sets the spacing in pixels between grid columns.
public int ColumnSpacing { get; set; }
Property Value
ColumnsProportions
Gets the collection of column proportions that define how columns divide available space.
[Browsable(false)]
public ObservableCollection<Proportion> ColumnsProportions { get; }
Property Value
DefaultColumnProportion
Gets or sets the default proportion used for columns when not explicitly specified.
[Browsable(false)]
public Proportion DefaultColumnProportion { get; set; }
Property Value
DefaultRowProportion
Gets or sets the default proportion used for rows when not explicitly specified.
[Browsable(false)]
public Proportion DefaultRowProportion { get; set; }
Property Value
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
GridLinesY
Gets the Y coordinates of the horizontal grid lines.
[Browsable(false)]
public List<int> GridLinesY { get; }
Property Value
GridSelectionMode
Gets or sets the selection mode for the grid (rows, columns, cells, or none).
public GridSelectionMode GridSelectionMode { get; set; }
Property Value
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
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
RowSpacing
Gets or sets the spacing in pixels between grid rows.
public int RowSpacing { get; set; }
Property Value
RowsProportions
Gets the collection of row proportions that define how rows divide available space.
[Browsable(false)]
public ObservableCollection<Proportion> RowsProportions { get; }
Property Value
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
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
ShowGridLines
Gets or sets a value indicating whether grid lines are displayed for debugging purposes.
public bool ShowGridLines { get; set; }
Property Value
Methods
ApplyStyle(WidgetStyle)
Applies the specified widget style to this grid.
protected override void ApplyStyle(WidgetStyle style)
Parameters
styleWidgetStyleThe widget style to apply.
CopyFrom(Widget)
Copies the grid properties and column/row proportions from another grid.
protected override void CopyFrom(Widget w)
Parameters
wWidgetThe source grid to copy from.
GetCellLocationX(int)
Gets the X coordinate of the cell at the specified column.
public int GetCellLocationX(int col)
Parameters
colintThe 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
rowintThe 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
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
widgetWidgetThe 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
colintThe 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
widgetWidgetThe 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
indexintThe 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
widgetWidgetThe 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
indexintThe 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
rowintThe 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
widgetWidgetThe 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
contextRenderContextThe 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
SetColumnSpan(Widget, int)
Sets the column span for the specified widget within the grid.
public static void SetColumnSpan(Widget widget, int value)
Parameters
SetRow(Widget, int)
Sets the row index for the specified widget within the grid.
public static void SetRow(Widget widget, int value)
Parameters
SetRowSpan(Widget, int)
Sets the row span for the specified widget within the grid.
public static void SetRowSpan(Widget widget, int value)
Parameters
Events
HoverIndexChanged
Occurs when the hovered row or column changes.
public event MyraEventHandler HoverIndexChanged
Event Type
SelectedIndexChanged
Occurs when the selected row or column changes.
public event MyraEventHandler SelectedIndexChanged