Skip to main content

HierarchicalRow<TModel> Class

Definition

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

A row in a Avalonia.Controls.HierarchicalTreeDataGridSource<T> that represents an item in a hierarchical data structure.

public class HierarchicalRow<TModel>

Inheritance: object -> NotifyingBase -> HierarchicalRow<TModel>

Implements: IExpander, IExpanderRow<>, IIndentedRow, IModelIndexableRow, IRow, IRow<>, INotifyPropertyChanged, IDisposable

Remarks

The Avalonia.Controls.Models.TreeDataGrid.HierarchicalRow<T> class represents a row in a hierarchical data structure within a TreeDataGrid. It manages the expanded/collapsed state of a row, its position within the hierarchy, and its relationship to its child rows.

This class coordinates with an Avalonia.Controls.Models.TreeDataGrid.IExpanderColumn<T> to handle the tree structure visualization, and an Avalonia.Controls.Models.TreeDataGrid.IExpanderRowController<T> to communicate row state changes back to the data source.

Each row maintains its position within the tree using an Avalonia.Controls.IndexPath, which represents the path from the root to this row in the hierarchy. This path is used for selection, sorting, and navigation operations.

Constructors

NameDescription
HierarchicalRow<TModel>No summary available.

HierarchicalRow<TModel> Constructor

public HierarchicalRow<TModel>(Avalonia.Controls.Models.TreeDataGrid.IExpanderRowController<TModel><TModel> controller, Avalonia.Controls.Models.TreeDataGrid.IExpanderColumn<TModel><TModel> expanderColumn, Avalonia.Controls.IndexPath modelIndex, TModel model, Comparison<TModel> comparison)

Parameters

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

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

modelIndex Avalonia.Controls.IndexPath

model TModel

comparison Comparison<TModel>

Methods

NameDescription
DisposeDisposes resources used by this row, including any child rows.
UpdateModelIndexUpdates the model index of this row by adding a delta to the last component of the model index path.
UpdateParentModelIndexUpdates this row's model index path when its parent's index path has changed.

Dispose Method

Disposes resources used by this row, including any child rows.

public void Dispose()

UpdateModelIndex Method

Updates the model index of this row by adding a delta to the last component of the model index path.

public void UpdateModelIndex(int delta)

Parameters

delta int

The amount to add to the model index.

Remarks

This method is used when items are inserted or removed from the data source, causing the indices of subsequent items to shift. After updating this row's index, it recursively updates the indices of all child rows.

UpdateParentModelIndex Method

Updates this row's model index path when its parent's index path has changed.

public void UpdateParentModelIndex(Avalonia.Controls.IndexPath parentIndex)

Parameters

parentIndex Avalonia.Controls.IndexPath

The new parent index path.

Remarks

This method is called when a parent row's index path changes, requiring all child rows to update their paths accordingly. After updating this row's path, it recursively updates the paths of all child rows.

Properties

NameDescription
ChildrenGets the row's visible child rows.
HeaderGets the row header.
HeightGets or sets the height of the row.
IndentGets the indentation level of the row.
IsExpandedGets or sets a value indicating whether the row is expanded to show its child rows.
ModelGets the model object associated with this row.
ModelIndexGets the index of the model relative to its parent.
ModelIndexPathGets the index path of the model in the data source.
ShowExpanderGets a value indicating whether the expander button should be shown for this row.

Children Property

Gets the row's visible child rows.

public System.Collections.Generic.IReadOnlyList<Avalonia.Controls.Models.TreeDataGrid.HierarchicalRow<TModel><TModel>> Children { get; set; }

Remarks

Returns the collection of child rows when the row is expanded, or null when the row is collapsed. Child rows are created on-demand when the row is first expanded.

Header Property

Gets the row header.

public object Header { get; set; }

Remarks

Returns the row's Avalonia.Controls.Models.TreeDataGrid.HierarchicalRow<T>.ModelIndexPath, which can be used to identify the row within the hierarchy.

Height Property

Gets or sets the height of the row.

public Avalonia.Controls.GridLength Height { get; set; }

Remarks

Currently, row height is always auto-sized and setting this property has no effect.

Indent Property

Gets the indentation level of the row.

public int Indent { get; set; }

Remarks

The indentation level is determined by the depth of the row in the hierarchical structure. Root items have an indent of 0, their children have an indent of 1, and so on.

IsExpanded Property

Gets or sets a value indicating whether the row is expanded to show its child rows.

public bool IsExpanded { get; set; }

Remarks

When set to true, the row will attempt to expand and show its child rows. If the row has no children, the expander will be hidden.

Setting this property will notify the controller of the state change, which will update the visual representation in the UI.

Model Property

Gets the model object associated with this row.

public TModel Model { get; set; }

ModelIndex Property

Gets the index of the model relative to its parent.

public int ModelIndex { get; set; }

Remarks

To retrieve the index path to the model from the root data source, see Avalonia.Controls.Models.TreeDataGrid.HierarchicalRow<T>.ModelIndexPath.

ModelIndexPath Property

Gets the index path of the model in the data source.

public Avalonia.Controls.IndexPath ModelIndexPath { get; set; }

Remarks

This index path uniquely identifies the row within the hierarchical structure, starting from the root. It represents the sequence of child indices needed to navigate to this row.

ShowExpander Property

Gets a value indicating whether the expander button should be shown for this row.

public bool ShowExpander { get; set; }

Remarks

The expander button is shown when the row has children that can be expanded. This property's initial value is determined by querying the expander column's Avalonia.Controls.Models.TreeDataGrid.IExpanderColumn<T>.HasChildren(`0) method.

If a row is expanded but turns out to have no children, the expander will be hidden.

Events

NameDescription
PropertyChangedOccurs when a property value changes. Inherited from NotifyingBase.