Skip to main content

CellRenderer Class

Definition​

Assembly:Avalonia.Controls.TreeDataGrid
Package:Avalonia.Controls.TreeDataGrid

Base class for cell renderers that draw cell content directly without creating per-cell controls.

public class CellRenderer

Inheritance: object -> CellRenderer

Remarks​

When a column has a Avalonia.Controls.CellRenderer, the Avalonia.Controls.Primitives.TreeDataGridCellsPresenter renders cells directly rather than creating individual control elements for each cell. This can significantly improve performance for columns that display simple content such as text.

This is an abstract class rather than an interface so that methods with defaults can be added in the future without breaking existing implementations.

Methods​

NameDescription
CommitEditCommits changes made to the edit control back to the model.
CreateEditControlCreates an edit control when a drawn cell enters edit mode.
MeasureContentMeasures the content of a drawn cell.
RenderContentRenders the content of a drawn cell.

CommitEdit Method​

Commits changes made to the edit control back to the model.

public void CommitEdit(Avalonia.Controls.Control editControl)

Parameters​

editControl Avalonia.Controls.Control

The edit control.

CreateEditControl Method​

Creates an edit control when a drawn cell enters edit mode.

public Avalonia.Controls.Control CreateEditControl(object dataContext)

Parameters​

dataContext object

The row's data model.

Returns​

Avalonia.Controls.Control

The edit control, or null if not editable.

MeasureContent Method​

Measures the content of a drawn cell.

public Avalonia.Size MeasureContent(Avalonia.Controls.Control owner, object dataContext, Avalonia.Size availableSize)

Parameters​

owner Avalonia.Controls.Control

The presenter control (for reading inherited font properties).

dataContext object

The row's data model.

availableSize Avalonia.Size

Available size constraint.

Returns​

Avalonia.Size

The desired size of the cell content.

RenderContent Method​

Renders the content of a drawn cell.

public void RenderContent(Avalonia.Controls.Control owner, Avalonia.Media.DrawingContext context, object dataContext, Avalonia.Rect bounds, bool isSelected)

Parameters​

owner Avalonia.Controls.Control

The presenter control.

context Avalonia.Media.DrawingContext

The drawing context.

dataContext object

The row's data model.

bounds Avalonia.Rect

The cell bounds to render within.

isSelected bool

Whether the cell/row is selected.