TreeDataGridElementFactory Class
Definition
Factory class responsible for creating and recycling UI elements used in the Avalonia.Controls.TreeDataGrid control.
public class TreeDataGridElementFactory
Remarks
The TreeDataGridElementFactory manages the creation of UI elements in the TreeDataGrid, including rows, cells, and column headers. It implements an element recycling strategy that improves performance by reusing existing UI elements rather than creating new ones whenever possible.
This class can be extended to customize the creation and recycling of TreeDataGrid elements by overriding the Avalonia.Controls.Primitives.TreeDataGridElementFactory.CreateElement(object), Avalonia.Controls.Primitives.TreeDataGridElementFactory.GetDataRecycleKey(object), and Avalonia.Controls.Primitives.TreeDataGridElementFactory.GetElementRecycleKey(Avalonia.Controls.Control) methods.
Constructors
| Name | Description |
|---|---|
| TreeDataGridElementFactory | No summary available. |
TreeDataGridElementFactory Constructor
public TreeDataGridElementFactory()
Methods
| Name | Description |
|---|---|
| GetOrCreateElement | Gets an existing recycled element or creates a new element for the specified data. |
| RecycleElement | Recycles an element for later reuse. |
GetOrCreateElement Method
Gets an existing recycled element or creates a new element for the specified data.
public Avalonia.Controls.Control GetOrCreateElement(object data, Avalonia.Controls.Control parent)
Parameters
data object
The TreeDataGrid model for which to get or create an element, e.g. Avalonia.Controls.Models.TreeDataGrid.ICell or Avalonia.Controls.Models.TreeDataGrid.CheckBoxCell.
parent Avalonia.Controls.Control
The parent control that will host the element, e.g. a Avalonia.Controls.Primitives.TreeDataGridRow.
Returns
A control that can be used to display the specified data.
Remarks
This method first attempts to reuse an existing element from the recycle pool. It tries to find an element with the same parent, then an element with no parent, and finally creates a new element if necessary.
The returned element will be ready to use but may need to be further configured with specific data, for example the DataContext is not set by this method.
RecycleElement Method
Recycles an element for later reuse.
public void RecycleElement(Avalonia.Controls.Control element)
Parameters
element Avalonia.Controls.Control
The control element to recycle.
Remarks
When an element is no longer needed (e.g., when it scrolls out of view), this method should be called to add it to the recycle pool. The element can then be reused later when a similar element is needed, improving performance by reducing the need to create new elements.
Recycled elements should be in a clean state, with any data-specific state cleared.