Skip to main content

HierarchicalRows<TModel> Class

Definition

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

Manages a collection of hierarchical rows in a Avalonia.Controls.HierarchicalTreeDataGridSource<T>.

public class HierarchicalRows<TModel>

Inheritance: ReadOnlyListBase<HierarchicalRow<>> -> HierarchicalRows<TModel>

Implements: IExpanderRowController<>, IRows, IEnumerable<IRow>, IReadOnlyCollection<IRow>, IReadOnlyList<IRow>, IEnumerable, INotifyCollectionChanged, IDisposable

Remarks

The Avalonia.Controls.Models.TreeDataGrid.HierarchicalRows<T> class is responsible for maintaining a flattened view of hierarchical data for display in a TreeDataGrid. It manages the relationships between rows, handles expansion and collapse operations, and synchronizes the view with the underlying data source.

This class serves as both a collection of rows and a controller for row operations. It maintains a flattened list of rows that represents the current visual state of the tree, taking into account which nodes are expanded or collapsed.

When rows are expanded or collapsed, this class manages the insertion and removal of child rows from the flattened list and raises the appropriate collection changed events.

Constructors

NameDescription
HierarchicalRows<TModel>No summary available.

HierarchicalRows<TModel> Constructor

public HierarchicalRows<TModel>(Avalonia.Controls.Models.TreeDataGrid.IExpanderRowController<TModel><TModel> controller, Avalonia.Controls.TreeDataGridItemsSourceView<T><TModel> items, Avalonia.Controls.Models.TreeDataGrid.IExpanderColumn<TModel><TModel> expanderColumn, Comparison<TModel> comparison)

Parameters

controller Avalonia.Controls.Models.TreeDataGrid.IExpanderRowController<TModel><TModel>

items Avalonia.Controls.TreeDataGridItemsSourceView<T><TModel>

expanderColumn Avalonia.Controls.Models.TreeDataGrid.IExpanderColumn<TModel><TModel>

comparison Comparison<TModel>

Methods

NameDescription
CollapseCollapses a row identified by its index path.
DisposeReleases resources used by the Avalonia.Controls.Models.TreeDataGrid.HierarchicalRows<T>.
ExpandExpands a row identified by its index path.
FilterNo summary available.
GetEnumeratorNo summary available.
GetParentRowIndexGets the row index of a parent row given a child's model index.
GetRowAtGets the row index and vertical position for a given vertical offset.
ModelIndexToRowIndexConverts a model index path to a flattened row index.
RealizeCellCreates a cell for the specified column at the specified row index.
RefreshFilterRefreshes the current filter applied to the collection.
RowIndexToModelIndexConverts a flattened row index to a model index path.
SetItemsNo summary available.
SortNo summary available.
UnrealizeCellReleases resources used by a cell when it is no longer visible.

Collapse Method

Collapses a row identified by its index path.

public void Collapse(Avalonia.Controls.IndexPath index)

Parameters

index Avalonia.Controls.IndexPath

The index path identifying the row to collapse.

Remarks

This method navigates through the tree structure using the index path to find the target row, then collapses it to hide its children.

If any part of the path cannot be found, the operation silently fails.

Dispose Method

Releases resources used by the Avalonia.Controls.Models.TreeDataGrid.HierarchicalRows<T>.

public void Dispose()

Remarks

Disposes the root rows collection and clears all event subscriptions.

Expand Method

Expands a row identified by its index path.

public void Expand(Avalonia.Controls.IndexPath index)

Parameters

index Avalonia.Controls.IndexPath

The index path identifying the row to expand.

Remarks

This method navigates through the tree structure using the index path to find the target row, then expands it to show its children.

If any part of the path cannot be found, the operation silently fails.

Filter Method

public void Filter(Func<TModel, bool> filter)

Parameters

filter Func<TModel, bool>

GetEnumerator Method

public System.Collections.Generic.IEnumerator<Avalonia.Controls.Models.TreeDataGrid.HierarchicalRow<TModel><TModel>> GetEnumerator()

Returns

System.Collections.Generic.IEnumerator<Avalonia.Controls.Models.TreeDataGrid.HierarchicalRow<TModel><TModel>>

GetParentRowIndex Method

Gets the row index of a parent row given a child's model index.

public int GetParentRowIndex(Avalonia.Controls.IndexPath modelIndex)

Parameters

modelIndex Avalonia.Controls.IndexPath

The model index of a child row.

Returns

int

The row index of the parent row, or -1 if not found.

Remarks

This method is useful for operations that need to work with a child row's parent, such as expanding to reveal a specific item.

GetRowAt Method

Gets the row index and vertical position for a given vertical offset.

public ValueTuple<int, double> GetRowAt(double y)

Parameters

y double

The vertical offset in pixels.

Returns

ValueTuple<int, double>

A tuple containing the row index and the vertical position of the row.

Remarks

This method is used for virtualization to determine which row should be displayed at a particular scroll position.

ModelIndexToRowIndex Method

Converts a model index path to a flattened row index.

public int ModelIndexToRowIndex(Avalonia.Controls.IndexPath modelIndex)

Parameters

modelIndex Avalonia.Controls.IndexPath

The model index path.

Returns

int

The corresponding row index in the flattened collection, or -1 if not found.

Remarks

This method is used to locate a row in the flattened collection when only its hierarchical position (model index path) is known.

RealizeCell Method

Creates a cell for the specified column at the specified row index.

public Avalonia.Controls.Models.TreeDataGrid.ICell RealizeCell(Avalonia.Controls.Models.TreeDataGrid.IColumn column, int columnIndex, int rowIndex)

Parameters

column Avalonia.Controls.Models.TreeDataGrid.IColumn

The column for which to create a cell.

columnIndex int

The index of the column.

rowIndex int

The index of the row.

Returns

Avalonia.Controls.Models.TreeDataGrid.ICell

A new cell instance.

Remarks

This method is used during UI virtualization to create cell instances as they become visible. The created cells are bound to the appropriate row model.

Exceptions

RefreshFilter Method

Refreshes the current filter applied to the collection.

public void RefreshFilter()

Remarks

Call this method if the filter predicate depends on external state which has changed, to re-apply the filter to the collection.

RowIndexToModelIndex Method

Converts a flattened row index to a model index path.

public Avalonia.Controls.IndexPath RowIndexToModelIndex(int rowIndex)

Parameters

rowIndex int

The row index in the flattened collection.

Returns

Avalonia.Controls.IndexPath

The corresponding model index path, or an empty path if not found.

Remarks

This method is used to determine the hierarchical position of a row when only its position in the flattened collection is known.

SetItems Method

public void SetItems(Avalonia.Controls.TreeDataGridItemsSourceView<T><TModel> items)

Parameters

items Avalonia.Controls.TreeDataGridItemsSourceView<T><TModel>

Sort Method

public void Sort(Comparison<TModel> comparison)

Parameters

comparison Comparison<TModel>

UnrealizeCell Method

Releases resources used by a cell when it is no longer visible.

public void UnrealizeCell(Avalonia.Controls.Models.TreeDataGrid.ICell cell, int rowIndex, int columnIndex)

Parameters

cell Avalonia.Controls.Models.TreeDataGrid.ICell

The cell to unrealize.

rowIndex int

The index of the row that the cell belongs to.

columnIndex int

The index of the column that the cell belongs to.

Remarks

This method is called during UI virtualization when a cell scrolls out of view. If the cell implements IDisposable, it is disposed.

Properties

NameDescription
CountGets the number of rows in the flattened collection.
IsFilteredNo summary available.
ItemNo summary available.

Count Property

Gets the number of rows in the flattened collection.

public int Count { get; set; }

Remarks

This count represents the total number of visible rows in the tree, including both root rows and the expanded children of those rows.

IsFiltered Property

public bool IsFiltered { get; set; }

Item Property

public Avalonia.Controls.Models.TreeDataGrid.HierarchicalRow<TModel><TModel> Item { get; set; }

Events

NameDescription
CollectionChangedOccurs when the contents of the flattened collection change.

CollectionChanged Event

Occurs when the contents of the flattened collection change.

public event System.Collections.Specialized.NotifyCollectionChangedEventHandler CollectionChanged