Selaa lähdekoodia

Fix scrolling to item when size == 0,0

When virtualized presenter size == 0,0 no containers will be
materialized so no container will be found.

Fixes #591.
Steven Kirk 9 vuotta sitten
vanhempi
sitoutus
1c88b3bd85

+ 1 - 1
src/Avalonia.Controls/Presenters/ItemVirtualizerSimple.cs

@@ -475,7 +475,7 @@ namespace Avalonia.Controls.Presenters
                 // is only partially visible due to differing item sizes. If the container is only 
                 // partially visible, scroll again. Don't do this if there's no layout manager:
                 // it means we're running a unit test.
-                if (layoutManager != null)
+                if (container != null && layoutManager != null)
                 {
                     layoutManager.ExecuteLayoutPass();
 

+ 17 - 0
tests/Avalonia.Controls.UnitTests/Presenters/ItemsPresenterTests_Virtualization_Simple.cs

@@ -505,6 +505,23 @@ namespace Avalonia.Controls.UnitTests.Presenters
             Assert.Equal(0, ((IVirtualizingPanel)target.Panel).PixelOffset);
         }
 
+        [Fact]
+        public void Scrolling_To_Item_In_Zero_Sized_Presenter_Doesnt_Throw()
+        {
+            using (UnitTestApplication.Start(TestServices.RealLayoutManager))
+            {
+                var target = CreateTarget(itemCount: 10);
+                var items = (IList<string>)target.Items;
+
+                target.ApplyTemplate();
+                target.Measure(Size.Empty);
+                target.Arrange(Rect.Empty);
+
+                // Check for issue #591: this should not throw.
+                target.ScrollIntoView(items[0]);
+            }
+        }
+
         public class Vertical
         {
             [Fact]