From f24b7da0d329f8152afb8e99da67d56adeaff6ef Mon Sep 17 00:00:00 2001 From: sdoroff Date: Thu, 26 Jul 2018 01:24:05 -0400 Subject: [PATCH] Fixes scrolling bug in grouped DataGrids Fixes #5 --- samples/DataGridSample/DataGridSample.csproj | 4 +-- .../Avalonia.DataGrid.Themes.Default.csproj | 2 +- .../Avalonia.DataGrid.csproj | 2 +- src/Avalonia.DataGrid/DataGrid.cs | 8 ++++-- .../DataGridRowGroupHeader.cs | 2 +- .../Primitives/DataGridRowsPresenter.cs | 26 ++++++++++++++++++- 6 files changed, 36 insertions(+), 8 deletions(-) diff --git a/samples/DataGridSample/DataGridSample.csproj b/samples/DataGridSample/DataGridSample.csproj index b8b3123989..d5ce1fd88b 100644 --- a/samples/DataGridSample/DataGridSample.csproj +++ b/samples/DataGridSample/DataGridSample.csproj @@ -12,8 +12,8 @@ - - + + diff --git a/src/Avalonia.DataGrid.Themes.Default/Avalonia.DataGrid.Themes.Default.csproj b/src/Avalonia.DataGrid.Themes.Default/Avalonia.DataGrid.Themes.Default.csproj index 3175f9d34d..b6c808893e 100644 --- a/src/Avalonia.DataGrid.Themes.Default/Avalonia.DataGrid.Themes.Default.csproj +++ b/src/Avalonia.DataGrid.Themes.Default/Avalonia.DataGrid.Themes.Default.csproj @@ -5,7 +5,7 @@ - + diff --git a/src/Avalonia.DataGrid/Avalonia.DataGrid.csproj b/src/Avalonia.DataGrid/Avalonia.DataGrid.csproj index 98c6d2e5a5..f1f6eb3a09 100644 --- a/src/Avalonia.DataGrid/Avalonia.DataGrid.csproj +++ b/src/Avalonia.DataGrid/Avalonia.DataGrid.csproj @@ -5,7 +5,7 @@ - + diff --git a/src/Avalonia.DataGrid/DataGrid.cs b/src/Avalonia.DataGrid/DataGrid.cs index 5fd2b973d3..c394f27966 100644 --- a/src/Avalonia.DataGrid/DataGrid.cs +++ b/src/Avalonia.DataGrid/DataGrid.cs @@ -1512,7 +1512,7 @@ namespace Avalonia.Controls { get { - return RowsPresenterAvailableSize?.Height ?? 0; + return RowsPresenterEstimatedAvailableHeight ?? 0; } } @@ -1800,7 +1800,11 @@ namespace Avalonia.Controls _rowsPresenterAvailableSize = value; } } - + internal double? RowsPresenterEstimatedAvailableHeight + { + get; + set; + } internal double[] RowGroupSublevelIndents { diff --git a/src/Avalonia.DataGrid/DataGridRowGroupHeader.cs b/src/Avalonia.DataGrid/DataGridRowGroupHeader.cs index f71d7a696c..5f53da41a8 100644 --- a/src/Avalonia.DataGrid/DataGridRowGroupHeader.cs +++ b/src/Avalonia.DataGrid/DataGridRowGroupHeader.cs @@ -468,7 +468,7 @@ namespace Avalonia.Controls // Do these even if the OwningGrid is null in case it could improve the Designer experience for a standalone DataGridRowGroupHeader RowGroupInfo.IsVisible = isVisible; } - else + else if(RowGroupInfo.IsVisible != isVisible) { OwningGrid.OnRowGroupHeaderToggled(this, isVisible, setCurrent); } diff --git a/src/Avalonia.DataGrid/Primitives/DataGridRowsPresenter.cs b/src/Avalonia.DataGrid/Primitives/DataGridRowsPresenter.cs index 59e3bb8a68..79ca527fd0 100644 --- a/src/Avalonia.DataGrid/Primitives/DataGridRowsPresenter.cs +++ b/src/Avalonia.DataGrid/Primitives/DataGridRowsPresenter.cs @@ -20,7 +20,20 @@ namespace Avalonia.Controls.Primitives get; set; } - + + private double _measureHeightOffset = 0; + private double CalculateEstimatedAvailableHeight(Size availableSize) + { + if(!Double.IsPositiveInfinity(availableSize.Height)) + { + return availableSize.Height + _measureHeightOffset; + } + else + { + return availableSize.Height; + } + } + /// /// Arranges the content of the . /// @@ -37,6 +50,16 @@ namespace Avalonia.Controls.Primitives return base.ArrangeOverride(finalSize); } + if(OwningGrid.RowsPresenterAvailableSize.HasValue) + { + var availableHeight = OwningGrid.RowsPresenterAvailableSize.Value.Height; + if(!Double.IsPositiveInfinity(availableHeight)) + { + _measureHeightOffset = finalSize.Height - availableHeight; + OwningGrid.RowsPresenterEstimatedAvailableHeight = finalSize.Height; + } + } + OwningGrid.OnFillerColumnWidthNeeded(finalSize.Width); double rowDesiredWidth = OwningGrid.ColumnsInternal.VisibleEdgedColumnsWidth + OwningGrid.ColumnsInternal.FillerColumn.FillerWidth; @@ -97,6 +120,7 @@ namespace Avalonia.Controls.Primitives // The DataGrid uses the RowsPresenter available size in order to autogrow // and calculate the scrollbars OwningGrid.RowsPresenterAvailableSize = availableSize; + OwningGrid.RowsPresenterEstimatedAvailableHeight = CalculateEstimatedAvailableHeight(availableSize); OwningGrid.OnRowsMeasure();