Esempio n. 1
0
        public void TestScrollToNeighborElement(bool virtualizeItems)
        {
            var stackSize = new Vector3(100, 200, 300);
            var childSize1 = new Vector3(50, 150, 250);
            var childSize2 = new Vector3(150, 250, 350);
            var childSize3 = new Vector3(250, 250, 350);

            var stackPanel = new StackPanel { Size = stackSize, ItemVirtualizationEnabled = virtualizeItems, Orientation = Orientation.Horizontal };

            var child1 = new StackPanel { Size = childSize1 };
            var child2 = new StackPanel { Size = childSize2 };
            var child3 = new StackPanel { Size = childSize3 };

            stackPanel.Children.Add(child1);
            stackPanel.Children.Add(child2);
            stackPanel.Children.Add(child3);

            stackPanel.Arrange(Vector3.Zero, false);

            // pre-arranged
            stackPanel.ScrollToNextLine(Orientation.Horizontal);
            Assert.AreEqual(1, stackPanel.ScrollPosition);

            stackPanel.ScrollToPreviousLine(Orientation.Horizontal);
            Assert.AreEqual(0, stackPanel.ScrollPosition);

            stackPanel.ScrolllToElement(1.6f);
            stackPanel.ScrollToPreviousLine(Orientation.Horizontal);
            Assert.AreEqual(1, stackPanel.ScrollPosition);

            stackPanel.ScrolllToElement(1.6f);
            stackPanel.ScrollToNextLine(Orientation.Horizontal);
            Assert.AreEqual(2, stackPanel.ScrollPosition);

            // reset scrolling
            stackPanel.ScrollToBeginning(Orientation.Horizontal);
            stackPanel.Arrange(Vector3.Zero, false);

            // post arranged
            stackPanel.InvalidateArrange();
            stackPanel.ScrollToNextLine(Orientation.Horizontal);
            Assert.AreEqual(0, stackPanel.ScrollPosition);
            stackPanel.Arrange(Vector3.Zero, false);
            Assert.AreEqual(1, stackPanel.ScrollPosition);

            stackPanel.InvalidateArrange();
            stackPanel.ScrollToPreviousLine(Orientation.Horizontal);
            Assert.AreEqual(1, stackPanel.ScrollPosition);
            stackPanel.Arrange(Vector3.Zero, false);
            Assert.AreEqual(0, stackPanel.ScrollPosition);

            stackPanel.ScrolllToElement(1.6f);
            stackPanel.Arrange(Vector3.Zero, false);
            stackPanel.InvalidateArrange();
            stackPanel.ScrollToPreviousLine(Orientation.Horizontal);
            Assert.AreEqual(1.6f, stackPanel.ScrollPosition);
            stackPanel.Arrange(Vector3.Zero, false);
            Assert.AreEqual(1, stackPanel.ScrollPosition);

            stackPanel.ScrolllToElement(1.6f);
            stackPanel.Arrange(Vector3.Zero, false);
            stackPanel.InvalidateArrange();
            stackPanel.ScrollToNextLine(Orientation.Horizontal);
            Assert.AreEqual(1.6f, stackPanel.ScrollPosition);
            stackPanel.Arrange(Vector3.Zero, false);
            Assert.AreEqual(2, stackPanel.ScrollPosition);
        }