Skip to content

Commit fdd1475

Browse files
committed
Call child realize from parent realize.
Previously we were calling r.g. `TreeDataGridCellsPresenter.UpdateRowIndex` from `TreeDataGridRow.Realize` instead of `TreeDataGridCellsPresenter.Realize`. This was causing the cells presenter to be stuck in a half-realized state. Make sure we call child `Realize` on realize and parent `UpdateRowIndex` only when updating row index. Added checks to ensure that `UpdateRowIndex` can't be called on an unrealized row or cell. Fixes #218
1 parent 1683c26 commit fdd1475

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

src/Avalonia.Controls.TreeDataGrid/Primitives/TreeDataGridCell.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,12 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
250250
base.OnPropertyChanged(change);
251251
}
252252

253-
internal void UpdateRowIndex(int index) => RowIndex = index;
253+
internal void UpdateRowIndex(int index)
254+
{
255+
if (RowIndex == -1)
256+
throw new InvalidOperationException("Cell is not realized.");
257+
RowIndex = index;
258+
}
254259

255260
internal void UpdateSelection(ITreeDataGridSelectionInteraction? selection)
256261
{

src/Avalonia.Controls.TreeDataGrid/Primitives/TreeDataGridCellsPresenter.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void Realize(int index)
3535
{
3636
if (RowIndex != -1)
3737
throw new InvalidOperationException("Row is already realized.");
38-
UpdateRowIndex(index);
38+
RowIndex = index;
3939
InvalidateMeasure();
4040
}
4141

@@ -51,6 +51,9 @@ public void UpdateRowIndex(int index)
5151
{
5252
if (index < 0 || Rows is null || index >= Rows.Count)
5353
throw new ArgumentOutOfRangeException(nameof(index));
54+
if (RowIndex == -1)
55+
throw new InvalidOperationException("Row is not realized.");
56+
5457
RowIndex = index;
5558

5659
foreach (var element in RealizedElements)

src/Avalonia.Controls.TreeDataGrid/Primitives/TreeDataGridRow.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ public void Realize(
8383
Rows = rows;
8484
DataContext = rows?[rowIndex].Model;
8585
IsSelected = selection?.IsRowSelected(rowIndex) ?? false;
86-
UpdateIndex(rowIndex);
86+
RowIndex = rowIndex;
8787
UpdateSelection(selection);
88+
CellsPresenter?.Realize(rowIndex);
8889
_treeDataGrid?.RaiseRowPrepared(this, RowIndex);
8990
}
9091

@@ -95,6 +96,9 @@ public void Realize(
9596

9697
public void UpdateIndex(int index)
9798
{
99+
if (RowIndex == -1)
100+
throw new InvalidOperationException("Row is not realized.");
101+
98102
RowIndex = index;
99103
CellsPresenter?.UpdateRowIndex(index);
100104
}
@@ -107,6 +111,7 @@ public void Unrealize()
107111
IsSelected = false;
108112
CellsPresenter?.Unrealize();
109113
}
114+
110115
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
111116
{
112117
_treeDataGrid = this.FindLogicalAncestorOfType<TreeDataGrid>();

0 commit comments

Comments
 (0)