From d581bfe69e9dbb05eef709e8753cd93f4600b548 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Mon, 4 Jul 2016 23:40:09 +0200 Subject: [PATCH] Limit initial measure of virtualized list. Prevents all items being materialized when virtualized control is measured with infinity. --- .../Presenters/ItemsPresenter.cs | 20 +++++++++++++++++++ .../VirtualizingStackPanel.cs | 2 -- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Controls/Presenters/ItemsPresenter.cs b/src/Avalonia.Controls/Presenters/ItemsPresenter.cs index ffc2680c83..9a7df4e337 100644 --- a/src/Avalonia.Controls/Presenters/ItemsPresenter.cs +++ b/src/Avalonia.Controls/Presenters/ItemsPresenter.cs @@ -91,6 +91,26 @@ namespace Avalonia.Controls.Presenters _virtualizer?.ScrollIntoView(item); } + protected override Size MeasureOverride(Size availableSize) + { + // If infinity is passed as the available size and we're virtualized then we need to + // fill the available space, but to do that we *don't* want to materialize all our + // items! Take a look at the root of the tree for a MaxClientSize and use that as + // the available size. + if (availableSize == Size.Infinity && VirtualizationMode != ItemVirtualizationMode.None) + { + var window = VisualRoot as Window; + + if (window != null) + { + availableSize = window.PlatformImpl.MaxClientSize; + } + } + + Panel.Measure(availableSize); + return Panel.DesiredSize; + } + /// protected override void PanelCreated(IPanel panel) { diff --git a/src/Avalonia.Controls/VirtualizingStackPanel.cs b/src/Avalonia.Controls/VirtualizingStackPanel.cs index 46a17d601f..840ed06c73 100644 --- a/src/Avalonia.Controls/VirtualizingStackPanel.cs +++ b/src/Avalonia.Controls/VirtualizingStackPanel.cs @@ -65,8 +65,6 @@ namespace Avalonia.Controls { if (availableSize != ((ILayoutable)this).PreviousMeasure) { - // TODO: We need to put a reasonable limit on this, probably based on the max - // window size. _availableSpace = availableSize; Controller?.UpdateControls(); }