Skip to content

Commit

Permalink
fix: Issue #5637 (#5638)
Browse files Browse the repository at this point in the history
* fix: Issue #5637 DataGridTemplateColumn incorrect select template when DataGridRow Recycled

* fixes(DataGrid): Binding Exception on DataGridTemplateColumn
  • Loading branch information
workgroupengineering authored and grokys committed Sep 29, 2021
1 parent ad2e68f commit 844cc25
Showing 1 changed file with 29 additions and 7 deletions.
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 int? MouseOverColumnIndex
}
}
}
}
}

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

0 comments on commit 844cc25

Please sign in to comment.