Browse Source

Merge pull request #5211 from donandren/issues/datagridinstackpanel

fix datagrid when in parent StackPanel ( or Grid.Row auto )
pull/5322/head
Dan Walmsley 6 years ago
committed by GitHub
parent
commit
963d94e9a5
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 35
      src/Avalonia.Controls.DataGrid/Primitives/DataGridRowsPresenter.cs

35
src/Avalonia.Controls.DataGrid/Primitives/DataGridRowsPresenter.cs

@ -3,14 +3,15 @@
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
using Avalonia.Media;
using System;
using System.Diagnostics;
using Avalonia.Layout;
using Avalonia.Media;
namespace Avalonia.Controls.Primitives
{
/// <summary>
/// Used within the template of a <see cref="T:Avalonia.Controls.DataGrid" /> to specify the
/// Used within the template of a <see cref="T:Avalonia.Controls.DataGrid" /> to specify the
/// location in the control's visual tree where the rows are to be added.
/// </summary>
public sealed class DataGridRowsPresenter : Panel
@ -22,25 +23,10 @@ namespace Avalonia.Controls.Primitives
}
private double _measureHeightOffset = 0;
private double _effectiveViewPortHeight = 0;
public DataGridRowsPresenter()
{
EffectiveViewportChanged += OnEffectiveViewportChanged;
}
private void OnEffectiveViewportChanged(object sender, Layout.EffectiveViewportChangedEventArgs e)
{
if (_effectiveViewPortHeight != e.EffectiveViewport.Height)
{
_effectiveViewPortHeight = e.EffectiveViewport.Height;
InvalidateMeasure();
}
}
private double CalculateEstimatedAvailableHeight(Size availableSize)
{
if(!Double.IsPositiveInfinity(availableSize.Height))
if (!Double.IsPositiveInfinity(availableSize.Height))
{
return availableSize.Height + _measureHeightOffset;
}
@ -66,10 +52,10 @@ namespace Avalonia.Controls.Primitives
return base.ArrangeOverride(finalSize);
}
if(OwningGrid.RowsPresenterAvailableSize.HasValue)
if (OwningGrid.RowsPresenterAvailableSize.HasValue)
{
var availableHeight = OwningGrid.RowsPresenterAvailableSize.Value.Height;
if(!Double.IsPositiveInfinity(availableHeight))
if (!Double.IsPositiveInfinity(availableHeight))
{
_measureHeightOffset = finalSize.Height - availableHeight;
OwningGrid.RowsPresenterEstimatedAvailableHeight = finalSize.Height;
@ -126,7 +112,14 @@ namespace Avalonia.Controls.Primitives
{
if (double.IsInfinity(availableSize.Height))
{
availableSize = availableSize.WithHeight(_effectiveViewPortHeight);
if (VisualRoot is TopLevel topLevel)
{
double maxHeight = topLevel.IsArrangeValid ?
topLevel.Bounds.Height :
LayoutHelper.ApplyLayoutConstraints(topLevel, availableSize).Height;
availableSize = availableSize.WithHeight(maxHeight);
}
}
if (availableSize.Height == 0 || OwningGrid == null)

Loading…
Cancel
Save