Esempio n. 1
0
        public void TestSurroudingAnchor(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);

            // checks in the scrolling direction

            stackPanel.ScrollToBeginning(Orientation.Horizontal);
            Utilities.AssertAreNearlyEqual(new Vector2(0, 50), stackPanel.GetSurroudingAnchorDistances(Orientation.Horizontal, 0));
            
            stackPanel.ScrolllToElement(0.5f);
            Utilities.AssertAreNearlyEqual(new Vector2(-25, 25), stackPanel.GetSurroudingAnchorDistances(Orientation.Horizontal, 0));

            stackPanel.ScrolllToElement(1f);
            Utilities.AssertAreNearlyEqual(new Vector2(0, 150), stackPanel.GetSurroudingAnchorDistances(Orientation.Horizontal, 0));

            stackPanel.ScrolllToElement(2 + 3/5f);
            Utilities.AssertAreNearlyEqual(new Vector2(-150, 100), stackPanel.GetSurroudingAnchorDistances(Orientation.Horizontal, 0));

            stackPanel.ScrollToEnd(Orientation.Horizontal);
            Utilities.AssertAreNearlyEqual(new Vector2(-150, 100), stackPanel.GetSurroudingAnchorDistances(Orientation.Horizontal, 0));

            // checks in other directions

            Assert.AreEqual(new Vector2(0, 200), stackPanel.GetSurroudingAnchorDistances(Orientation.Vertical, -1));
            Assert.AreEqual(new Vector2(-100, 100), stackPanel.GetSurroudingAnchorDistances(Orientation.Vertical, 100));
            Assert.AreEqual(new Vector2(-200, 0), stackPanel.GetSurroudingAnchorDistances(Orientation.Vertical, 500));

            Assert.AreEqual(new Vector2(0, 300), stackPanel.GetSurroudingAnchorDistances(Orientation.InDepth, -1));
            Assert.AreEqual(new Vector2(-150, 150), stackPanel.GetSurroudingAnchorDistances(Orientation.InDepth, 150));
            Assert.AreEqual(new Vector2(-300, 0), stackPanel.GetSurroudingAnchorDistances(Orientation.InDepth, 500));
        }