TreeDataGridItemsSourceView standardizes collection access and change notifications for TreeDataGrid internals.
It is public and useful in advanced scenarios where you build custom row/selection infrastructure.
Sources and selection internals need a predictable collection surface:
IEnumerable typesTreeDataGridItemsSourceView provides that abstraction.
Untyped:
using Avalonia.Controls;
var view = TreeDataGridItemsSourceView.GetOrCreate(items);
var count = view.Count;
var first = view[0];
Typed:
var typed = TreeDataGridItemsSourceView<MyModel>.GetOrCreate(items);
MyModel? value = typed.GetAt(0);
Given new TreeDataGridItemsSourceView(source):
source is IList: wraps directlysource is IEnumerable<object>: copies to List<object>source is non-generic IEnumerable: copies via Cast<object>()source implements INotifyCollectionChanged but not IList: throwsThis constraint exists because internals require stable index-based operations.
view.CollectionChanged += (_, e) =>
{
// react to Add/Remove/Move/Replace/Reset
};
Remember to dispose when done:
view.Dispose();
GetOrCreate PatternPrefer factory helpers when you may already hold a view:
var view = TreeDataGridItemsSourceView.GetOrCreate(maybeViewOrEnumerable);
Benefits:
Empty for null inputAvailable utility methods:
GetAt(int)IndexOf(object?)Countthis[int]KeyFromIndex / IndexFromKey exist but are currently not implemented.
Flat and hierarchical sources both use typed TreeDataGridItemsSourceView<TModel> internally to drive row model pipelines and selection model updates.
Feature behavior differs from expectations
Cause: one or more options in this scenario are configured differently (source type, column options, sort/selection/edit state).
Fix: compare your setup with the snippet in this article and verify runtime values on Source, Columns, and Selection.
Data changes are not visible in UI
Cause: model or collection notifications are missing, or a replaced collection/source is not re-bound.
Fix: ensure INotifyPropertyChanged/INotifyCollectionChanged flow is active and reassign Source after replacing underlying collections.