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)); }
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); }
public void TestScrollToExtrema(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.ScrollToEnd(Orientation.Horizontal); Utilities.AssertAreNearlyEqual(2 + 3 / 5f, stackPanel.ScrollPosition); stackPanel.ScrollToBeginning(Orientation.Horizontal); Utilities.AssertAreNearlyEqual(0, stackPanel.ScrollPosition); // post arranged stackPanel.InvalidateArrange(); stackPanel.ScrollToEnd(Orientation.Horizontal); Utilities.AssertAreNearlyEqual(0, stackPanel.ScrollPosition); stackPanel.Arrange(Vector3.Zero, false); Utilities.AssertAreNearlyEqual(2 + 3 / 5f, stackPanel.ScrollPosition); stackPanel.InvalidateArrange(); stackPanel.ScrollToBeginning(Orientation.Horizontal); Utilities.AssertAreNearlyEqual(2 + 3 / 5f, stackPanel.ScrollPosition); stackPanel.Arrange(Vector3.Zero, false); Utilities.AssertAreNearlyEqual(0, stackPanel.ScrollPosition); }
private static void TestScrollBarPosition(bool virtualizeChildren) { 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 = virtualizeChildren, Orientation = Orientation.Horizontal }; Assert.AreEqual(Vector3.Zero, stackPanel.ScrollBarPositions); 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); var reference = Vector3.Zero; stackPanel.ScrollToBeginning(Orientation.Horizontal); stackPanel.Arrange(Vector3.Zero, false); Assert.AreEqual(reference, stackPanel.ScrollBarPositions); reference[0] = 1; stackPanel.ScrollToEnd(Orientation.Horizontal); stackPanel.Arrange(Vector3.Zero, false); Assert.AreEqual(reference, stackPanel.ScrollBarPositions); stackPanel.ScrolllToElement(1); stackPanel.Arrange(Vector3.Zero, false); if (virtualizeChildren) { reference[0] = 1 / (2 + (childSize3.X - stackPanel.Size.X) / childSize3.X); } else { reference[0] = childSize1.X / (childSize1.X + childSize2.X + childSize3.X - stackPanel.Size.X); } Assert.AreEqual(reference, stackPanel.ScrollBarPositions); }