Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DataGridTemplateColumn Recycled Issue #5638

36 changes: 29 additions & 7 deletions src/Avalonia.Controls.DataGrid/DataGridRow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -378,13 +378,13 @@ internal bool IsSelected
}
}
}
}
}

internal Panel RootElement
{
get;
private set;
}
}

internal int Slot
{
Expand Down Expand Up @@ -638,7 +638,7 @@ internal void UpdatePseudoClasses()
PseudoClasses.Set(":editing", IsEditing);
PseudoClasses.Set(":invalid", !IsValid);
ApplyHeaderStatus();
}
}
}

//TODO Animation
Expand Down Expand Up @@ -896,7 +896,7 @@ internal void EnsureDetailsContentHeight()
_detailsElement.ContentHeight = _detailsDesiredHeight;
}
}
}
}

// Makes sure the _detailsDesiredHeight is initialized. We need to measure it to know what
// height we want to animate to. Subsequently, we just update that height in response to SizeChanged
Expand All @@ -919,7 +919,7 @@ private void EnsureDetailsDesiredHeight()

//TODO Cleanup
double? _previousDetailsHeight = null;

//TODO Animation
private void DetailsContent_HeightChanged(double newValue)
{
Expand Down Expand Up @@ -1022,7 +1022,7 @@ internal void SetDetailsVisibilityInternal(bool isVisible, bool raiseNotificatio
}
}
}

internal void ApplyDetailsTemplate(bool initializeDetailsPreferredHeight)
{
if (_detailsElement != null && AreDetailsVisible)
Expand Down Expand Up @@ -1066,7 +1066,7 @@ internal void ApplyDetailsTemplate(bool initializeDetailsPreferredHeight)
.Subscribe(DetailsContent_MarginChanged);

}

_detailsElement.Children.Add(_detailsContent);
}
}
Expand All @@ -1090,6 +1090,28 @@ internal void ApplyDetailsTemplate(bool initializeDetailsPreferredHeight)
}
}
}


protected override void OnPropertyChanged<T>(AvaloniaPropertyChangedEventArgs<T> change)
{
if (change.Property == DataContextProperty)
{
var owner = OwningGrid;
if (owner != null && this.IsRecycled)
{
var columns = owner.ColumnsItemsInternal;
var nc = columns.Count;
for (int ci = 0; ci < nc; ci++)
{
if (columns[ci] is DataGridTemplateColumn column)
{
column.RefreshCellContent((Control)this.Cells[column.Index].Content, nameof(DataGridTemplateColumn.CellTemplate));
}
}
}
}
base.OnPropertyChanged(change);
}

}

Expand Down