From 9bbca4acc3bc33ceefcf78ab70971744ed162f97 Mon Sep 17 00:00:00 2001 From: sdoroff Date: Tue, 4 Jun 2019 18:34:40 -0400 Subject: [PATCH] DataGrid RowDetail Fix Fixed a bug where row details would fail to show if the templated element had a non-empy margin --- src/Avalonia.Controls.DataGrid/DataGridRow.cs | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/Avalonia.Controls.DataGrid/DataGridRow.cs b/src/Avalonia.Controls.DataGrid/DataGridRow.cs index 8bc76543ba..04a1575486 100644 --- a/src/Avalonia.Controls.DataGrid/DataGridRow.cs +++ b/src/Avalonia.Controls.DataGrid/DataGridRow.cs @@ -881,10 +881,10 @@ namespace Avalonia.Controls && (double.IsNaN(_detailsContent.Height)) && (AreDetailsVisible) && (!double.IsNaN(_detailsDesiredHeight)) - && !DoubleUtil.AreClose(_detailsContent.Bounds.Height, _detailsDesiredHeight) + && !DoubleUtil.AreClose(_detailsContent.Bounds.Inflate(_detailsContent.Margin).Height, _detailsDesiredHeight) && Slot != -1) { - _detailsDesiredHeight = _detailsContent.Bounds.Height; + _detailsDesiredHeight = _detailsContent.Bounds.Inflate(_detailsContent.Margin).Height; if (true) { @@ -943,6 +943,16 @@ namespace Avalonia.Controls _previousDetailsHeight = newValue.Height; } } + private void DetailsContent_BoundsChanged(Rect newValue) + { + if(_detailsContent != null) + DetailsContent_SizeChanged(newValue.Inflate(_detailsContent.Margin)); + } + private void DetailsContent_MarginChanged(Thickness newValue) + { + if (_detailsContent != null) + DetailsContent_SizeChanged(_detailsContent.Bounds.Inflate(newValue)); + } //TODO Animation // Sets AreDetailsVisible on the row and animates if necessary @@ -997,7 +1007,7 @@ namespace Avalonia.Controls } } } - + internal void ApplyDetailsTemplate(bool initializeDetailsPreferredHeight) { if (_detailsElement != null && AreDetailsVisible) @@ -1023,8 +1033,11 @@ namespace Avalonia.Controls if (_detailsContent != null) { _detailsContentSizeSubscription = - _detailsContent.GetObservable(BoundsProperty) - .Subscribe(DetailsContent_SizeChanged); + System.Reactive.Disposables.StableCompositeDisposable.Create( + _detailsContent.GetObservable(BoundsProperty) + .Subscribe(DetailsContent_BoundsChanged), + _detailsContent.GetObservable(MarginProperty) + .Subscribe(DetailsContent_MarginChanged)); _detailsElement.Children.Add(_detailsContent); } } @@ -1053,4 +1066,4 @@ namespace Avalonia.Controls //TODO Styles -} \ No newline at end of file +}