Esempio n. 1
0
        public void TestScrollToNeighborScreen(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.ScrollToNextPage(Orientation.Horizontal);
            Utilities.AssertAreNearlyEqual(1 + 1 / 3f, stackPanel.ScrollPosition);

            stackPanel.ScrollToPreviousPage(Orientation.Horizontal);
            Utilities.AssertAreNearlyEqual(0, stackPanel.ScrollPosition);

            stackPanel.ScrolllToElement(1 + 2 / 3f);
            stackPanel.ScrollToPreviousPage(Orientation.Horizontal);
            Utilities.AssertAreNearlyEqual(1f, stackPanel.ScrollPosition);

            stackPanel.ScrolllToElement(1 + 2 / 3f);
            stackPanel.ScrollToNextPage(Orientation.Horizontal);
            Utilities.AssertAreNearlyEqual(2.2f, stackPanel.ScrollPosition);

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

            // post arranged
            stackPanel.InvalidateArrange();
            stackPanel.ScrollToNextPage(Orientation.Horizontal);
            Utilities.AssertAreNearlyEqual(0, stackPanel.ScrollPosition);
            stackPanel.Arrange(Vector3.Zero, false);
            Utilities.AssertAreNearlyEqual(1 + 1 / 3f, stackPanel.ScrollPosition);

            stackPanel.InvalidateArrange();
            stackPanel.ScrollToPreviousPage(Orientation.Horizontal);
            Utilities.AssertAreNearlyEqual(1 + 1 / 3f, stackPanel.ScrollPosition);
            stackPanel.Arrange(Vector3.Zero, false);
            Utilities.AssertAreNearlyEqual(0, stackPanel.ScrollPosition);

            stackPanel.ScrolllToElement(1 + 2 / 3f);
            stackPanel.Arrange(Vector3.Zero, false);
            stackPanel.InvalidateArrange();
            stackPanel.ScrollToPreviousPage(Orientation.Horizontal);
            Utilities.AssertAreNearlyEqual(1 + 2 / 3f, stackPanel.ScrollPosition);
            stackPanel.Arrange(Vector3.Zero, false);
            Utilities.AssertAreNearlyEqual(1, stackPanel.ScrollPosition);

            stackPanel.ScrolllToElement(1 + 2 / 3f);
            stackPanel.Arrange(Vector3.Zero, false);
            stackPanel.InvalidateArrange();
            stackPanel.ScrollToNextPage(Orientation.Horizontal);
            Utilities.AssertAreNearlyEqual(1 + 2 / 3f, stackPanel.ScrollPosition);
            stackPanel.Arrange(Vector3.Zero, false);
            Utilities.AssertAreNearlyEqual(2.2f, stackPanel.ScrollPosition);
        }