Diagnostics and Testing

This article covers practical workflows for validating TreeDataGrid behavior in development and CI.

Run the Sample App

dotnet run --project samples/TreeDataGridDemo/TreeDataGridDemo.csproj

Use sample scenarios to validate:

  • sorting, resizing, and editing interactions
  • row and cell selection behavior
  • expansion/collapse in hierarchical mode
  • row drag/drop scenarios

Build, Test, and Docs

dotnet restore Avalonia.Controls.TreeDataGrid.slnx
dotnet build Avalonia.Controls.TreeDataGrid.slnx -c Release --no-restore
dotnet test tests/Avalonia.Controls.TreeDataGrid.Tests/Avalonia.Controls.TreeDataGrid.Tests.csproj -c Release
./check-docs.sh

Package Validation

dotnet pack src/Avalonia.Controls.TreeDataGrid/Avalonia.Controls.TreeDataGrid.csproj -c Release -o artifacts/packages

Before publishing, verify:

  • package contains expected assemblies and themes
  • no public API regressions
  • docs site builds without warnings

Instrumenting Runtime Events

Use lifecycle events to inspect realization/edit paths:

grid.CellPrepared += (_, e) => Console.WriteLine($"CellPrepared C={e.ColumnIndex}, R={e.RowIndex}");
grid.CellClearing += (_, e) => Console.WriteLine($"CellClearing C={e.ColumnIndex}, R={e.RowIndex}");
grid.RowPrepared += (_, e) => Console.WriteLine($"RowPrepared R={e.RowIndex}");
grid.RowClearing += (_, e) => Console.WriteLine($"RowClearing R={e.RowIndex}");

This helps detect over-realization, incorrect reuse, and unexpected re-entry.

Regression Areas to Test

  • source replacement (Source swap, Items replacement)
  • sort then selection consistency
  • expand/collapse with selection preservation
  • drag/drop with sorted and unsorted constraints
  • virtualization correctness at high row counts

Troubleshooting

  • flaky selection tests Cause: asserting visuals instead of model indexes; prefer model-level assertions first.

  • drag/drop tests fail only in sorted mode Cause: sorted sources intentionally block automatic drag/drop move paths.

  • docs CI failures Cause: unresolved links or xrefs after API/article refactor.

API Coverage Checklist