protected override async Task LoadContent() { await base.LoadContent(); var uiImage = new UIImage(Asset.Load<Texture>("BorderButton")) { Borders = new Vector4(64, 64, 64, 64) }; var bi1 = new ImageElement { Source = uiImage, Height = 150 }; var bi2 = new ImageElement { Source = uiImage, Height = 300 }; var bi3 = new ImageElement { Source = uiImage, Height = 500 }; stackPanel = new StackPanel { Orientation = Orientation.Vertical }; stackPanel.Children.Add(bi1); stackPanel.Children.Add(bi2); stackPanel.Children.Add(bi3); UIComponent.RootElement = new ScrollViewer { Content = stackPanel, ScrollMode = ScrollingMode.HorizontalVertical }; }
protected override async Task LoadContent() { await base.LoadContent(); var image1 = new ImageElement { Source = new UIImage(Asset.Load<Texture>("BorderButtonCentered")) { Region = new Rectangle(256, 128, 512, 256), Borders = new Vector4(0.125f, 0.125f, 0.25f, 0.25f) }, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center }; var image2 = new ImageElement { Source = new UIImage(Asset.Load<Texture>("uv")) { Region = new Rectangle(0, 0, 512, 512) }, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center }; var image3 = new ImageElement { Source = new UIImage(Asset.Load<Texture>("uv")) { Region = new Rectangle(512, 0, 512, 512) }, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center }; var image4 = new ImageElement { Source = new UIImage(Asset.Load<Texture>("uv")) { Region = new Rectangle(0, 512, 512, 512) }, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center }; var image5 = new ImageElement { Source = new UIImage(Asset.Load<Texture>("uv")) { Region = new Rectangle(512, 512, 512, 512) }, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center }; stackPanel = new StackPanel { Orientation = Orientation.Vertical }; stackPanel.Children.Add(image1); stackPanel.Children.Add(image2); stackPanel.Children.Add(image3); stackPanel.Children.Add(image4); stackPanel.Children.Add(image5); UIComponent.RootElement = new ScrollViewer { Content = stackPanel }; }
protected override async Task LoadContent() { await base.LoadContent(); // build the randomStackPanel elements randomStackPanel = new StackPanel { Orientation = Orientation.Vertical }; for (int i = 0; i < 30; i++) randomStackPanel.Children.Add(CreateButton(0, i, 50, 1200, true)); // build the randomStackPanel elements virtualizedStackPanel = new StackPanel { Orientation = Orientation.Vertical, ItemVirtualizationEnabled = true }; for (int i = 0; i < 30; i++) virtualizedStackPanel.Children.Add(CreateButton(0, i, 75, 1200)); // build the uniform grid uniformGrid = new UniformGrid { Columns = 15, Rows = 20 }; for (int c = 0; c < uniformGrid.Columns; ++c) { for (int r = 0; r < uniformGrid.Rows; ++r) uniformGrid.Children.Add(CreateButton(c,r, 175, 300)); } // build the grid const int gridColumns = 10; const int gridRows = 10; grid = new Grid(); grid.LayerDefinitions.Add(new StripDefinition(StripType.Auto)); for (int i = 0; i < gridColumns; i++) grid.ColumnDefinitions.Add(new StripDefinition(StripType.Auto)); for (int i = 0; i < gridRows; i++) grid.RowDefinitions.Add(new StripDefinition(StripType.Auto)); for (int c = 0; c < gridColumns; ++c) { for (int r = 0; r < gridRows; ++r) grid.Children.Add(CreateButton(c, r, 50 + r * 30, 100 + c * 40)); } // build the scroll viewer scrollViewer = new TestScrollViewer { Name = "sv", Content = randomStackPanel, ScrollMode = ScrollingMode.HorizontalVertical, SnapToAnchors = true }; // set the scroll viewer as the root UIComponent.RootElement = scrollViewer; }
protected override async Task LoadContent() { await base.LoadContent(); var uiImages = Asset.Load<UIImageGroup>("UIImages"); var img1 = new ImageElement { Name = "UV 1 stack panel", Source = new UIImage(Asset.Load<Texture>("uv")) }; var img2 = new ImageElement { Name = "UV 2 stack panel", Source = new UIImage(Asset.Load<Texture>("uv")) }; img3 = new ImageElement { Name = "UV 3 stack panel", Source = new UIImage(Asset.Load<Texture>("uv")) }; stackPanel = new StackPanel { Orientation = Orientation.Vertical }; stackPanel.Children.Add(img1); stackPanel.Children.Add(img2); stackPanel.Children.Add(img3); var img4 = new ImageElement { Name = "UV grid", Source = new UIImage(Asset.Load<Texture>("uv")) }; var img5 = new ImageElement { Name = "UV grid 2", Source = new UIImage(Asset.Load<Texture>("uv")) }; var img6 = new ImageElement { Name = "Game screen grid", Source = uiImages["GameScreen"] }; img4.DependencyProperties.Set(GridBase.ColumnPropertyKey, 0); img4.DependencyProperties.Set(GridBase.RowPropertyKey, 0); img5.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1); img5.DependencyProperties.Set(GridBase.RowPropertyKey, 0); img6.DependencyProperties.Set(GridBase.ColumnPropertyKey, 0); img6.DependencyProperties.Set(GridBase.RowPropertyKey, 1); img6.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 2); grid = new UniformGrid { Columns = 2, Rows = 2 }; grid.Children.Add(img4); grid.Children.Add(img5); grid.Children.Add(img6); scrollViewer = new ScrollViewer { Content = grid, ScrollMode = ScrollingMode.HorizontalVertical}; contentDecorator = new ContentDecorator { Content = scrollViewer }; UIComponent.RootElement = contentDecorator; }
protected override async Task LoadContent() { await base.LoadContent(); var background = new Entity { new BackgroundComponent { Texture = Asset.Load<Texture>("ParadoxBackground") } }; Scene.AddChild(background); button1 = new Button { Content = new TextBlock { Text = "text block button 1", Font = Asset.Load<SpriteFont>("CourierNew12"), SynchronousCharacterGeneration = true } }; button1.SetCanvasRelativePosition(new Vector3(0.025f, 0.05f, 0f)); edit1 = new EditText(Services) { Text = "Edit text 1", Font = Asset.Load<SpriteFont>("CourierNew12"), SynchronousCharacterGeneration = true, }; edit1.SetCanvasRelativePosition(new Vector3(0.025f, 0.15f, 0f)); button2 = new Button { Content = new TextBlock { Text = "text block button 2", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15"), SynchronousCharacterGeneration = true } }; edit2 = new EditText(Services) { Text = "Edit text 2", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15"), }; stackPanel = new StackPanel { Children = { button2, edit2 }, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Orientation = Orientation.Horizontal }; stackPanel.SetCanvasRelativePosition(new Vector3(0.5f, 0.5f, 0f)); stackPanel.SetCanvasPinOrigin(new Vector3(.5f)); canvas = new Canvas { Children = {button1, edit1, stackPanel}, CanBeHitByUser = true }; button1.MouseOverStateChanged += (sender, args) => { triggeredButton1 = true; oldValueButton1 = args.OldValue; newValueButton1 = args.NewValue;}; button2.MouseOverStateChanged += (sender, args) => { triggeredButton2 = true;}; edit1.MouseOverStateChanged += (sender, args) => { triggeredEdit1 = true;}; edit2.MouseOverStateChanged += (sender, args) => { triggeredEdit2 = true;}; canvas.MouseOverStateChanged += (sender, args) => { triggeredCanvas = true;}; stackPanel.MouseOverStateChanged += (sender, args) => { triggeredStackPanel = true;}; UIComponent.RootElement = canvas; }
public void TestOffset() { 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 childSize4 = new Vector3(350, 250, 350); var stackPanel = new StackPanel { Size = stackSize, Orientation = Orientation.Horizontal }; Assert.AreEqual(Vector3.Zero, stackPanel.Offset); var child1 = new StackPanel { Size = childSize1 }; var child2 = new StackPanel { Size = childSize2 }; var child3 = new StackPanel { Size = childSize3 }; var child4 = new StackPanel { Size = childSize4 }; stackPanel.Children.Add(child1); stackPanel.Children.Add(child2); stackPanel.Children.Add(child3); stackPanel.Children.Add(child4); var refenceOffset = Vector3.Zero; // non virtualized children stackPanel.ScrolllToElement(1); stackPanel.Arrange(Vector3.Zero, false); refenceOffset[0] -= childSize1.X; Assert.AreEqual(refenceOffset, stackPanel.Offset); stackPanel.ScrolllToElement(2.5f); stackPanel.Arrange(Vector3.Zero, false); refenceOffset[0] -= childSize2.X + childSize3.X / 2; Assert.AreEqual(refenceOffset, stackPanel.Offset); stackPanel.ScrollToEnd(Orientation.Horizontal); stackPanel.Arrange(Vector3.Zero, false); refenceOffset[0] = -childSize1.X - childSize2.X - childSize3.X - childSize4.X + stackPanel.Size.X; Assert.IsTrue((refenceOffset-stackPanel.Offset).Length() < 0.001); // virtualized children refenceOffset[0] = 0; stackPanel.ScrolllToElement(0); stackPanel.ItemVirtualizationEnabled = true; stackPanel.Arrange(Vector3.Zero, false); Assert.AreEqual(refenceOffset, stackPanel.Offset); refenceOffset[0] = 0; stackPanel.ScrolllToElement(1); stackPanel.Arrange(Vector3.Zero, false); Assert.AreEqual(refenceOffset, stackPanel.Offset); refenceOffset[0] = -childSize3.X / 2; stackPanel.ScrolllToElement(2.5f); stackPanel.Arrange(Vector3.Zero, false); Assert.AreEqual(refenceOffset, stackPanel.Offset); stackPanel.ScrollToEnd(Orientation.Horizontal); stackPanel.Arrange(Vector3.Zero, false); refenceOffset[0] = -childSize4.X + stackPanel.Size.X; Assert.IsTrue((refenceOffset-stackPanel.Offset).Length() < 0.001); }
private static void TestScrollPosition(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 childSize4 = new Vector3(350, 250, 350); var stackPanel = new StackPanel { Size = stackSize, Orientation = Orientation.Horizontal, ItemVirtualizationEnabled = virtualizeChildren}; Assert.AreEqual(0f, stackPanel.ScrollPosition); var child1 = new StackPanel { Size = childSize1 }; var child2 = new StackPanel { Size = childSize2 }; var child3 = new StackPanel { Size = childSize3 }; var child4 = new StackPanel { Size = childSize4 }; stackPanel.Children.Add(child1); stackPanel.Children.Add(child2); stackPanel.Children.Add(child3); stackPanel.Children.Add(child4); float referencePosition = 0; stackPanel.ScrolllToElement(referencePosition); stackPanel.Arrange(Vector3.Zero, false); Assert.AreEqual(referencePosition, stackPanel.ScrollPosition); referencePosition = 1; stackPanel.ScrolllToElement(referencePosition); stackPanel.Arrange(Vector3.Zero, false); Assert.AreEqual(referencePosition, stackPanel.ScrollPosition); referencePosition = 2; stackPanel.ScrolllToElement(referencePosition); stackPanel.Arrange(Vector3.Zero, false); Assert.AreEqual(referencePosition, stackPanel.ScrollPosition); referencePosition = 2.3f; stackPanel.ScrolllToElement(referencePosition); stackPanel.Arrange(Vector3.Zero, false); Assert.AreEqual(referencePosition, stackPanel.ScrollPosition); stackPanel.ScrollToEnd(Orientation.Horizontal); referencePosition = 3 + (childSize4.X - stackSize.X) / childSize4.X; stackPanel.Arrange(Vector3.Zero, false); Assert.IsTrue(Math.Abs(referencePosition - stackPanel.ScrollPosition) < MathUtil.ZeroTolerance); }
public void TestBasicInvalidations() { var panel = new StackPanel(); var child = new StackPanel(); panel.Children.Add(child); // - test the properties that are not supposed to invalidate the object layout state UIElementLayeringTests.TestNoInvalidation(panel, () => child.DependencyProperties.Set(ZIndexPropertyKey, 37)); }
private void CreateShipSelectionPopup() { // Create "Please select your SpaceShip" text var pleaseSelectText = new TextBlock { Font = westernFont, TextSize = 48, TextColor = Color.White, Text = "Please select your ship", TextAlignment = TextAlignment.Center, WrapText = true }; // Layout elements in vertical StackPanel var contentStackpanel = new StackPanel { Orientation = Orientation.Vertical }; // Create and Add SpaceShip to the stack layout foreach (var ship in shipList) contentStackpanel.Children.Add(CreateShipButtonElement(ship)); // Uncomment those lines to have an example of stack panel item virtualization //var shipInitialCount = shipList.Count; //contentStackpanel.ItemVirtualizationEnabled = true; //for (int i = 0; i < 200; i++) //{ // shipList.Add(new SpaceShip { Name = shipList[i % shipInitialCount].Name }); // contentStackpanel.Children.Add(CreateShipButtonElement(shipList[shipList.Count - 1])); //} UpdateShipStatus(); var contentScrollView = new ScrollViewer { MaximumHeight = 425, Content = contentStackpanel, ScrollMode = ScrollingMode.Vertical, Margin = new Thickness(12, 10, 7, 10), Padding = new Thickness(0, 0, 6, 0), ScrollBarColor = Color.Orange }; var scrollViewerBackgroundImage = mainScreneImages["scroll_background"]; var scrollViewerDecorator = new ContentDecorator { BackgroundImage = scrollViewerBackgroundImage, Content = contentScrollView, }; scrollViewerDecorator.SetGridRow(2); var layoutGrid = new Grid(); layoutGrid.ColumnDefinitions.Add(new StripDefinition()); layoutGrid.RowDefinitions.Add(new StripDefinition(StripType.Auto)); layoutGrid.RowDefinitions.Add(new StripDefinition(StripType.Fixed, 10)); // white space layoutGrid.RowDefinitions.Add(new StripDefinition(StripType.Star)); layoutGrid.LayerDefinitions.Add(new StripDefinition()); layoutGrid.Children.Add(pleaseSelectText); layoutGrid.Children.Add(scrollViewerDecorator); var shipSelectPopupContent = new ContentDecorator { BackgroundImage = popupWindowImage, Content = layoutGrid, Padding = new Thickness(110, 120, 100, 140) }; // Create SpaceShip selection popup shipSelectPopup = new ModalElement { Visibility = Visibility.Collapsed, Content = shipSelectPopupContent }; shipSelectPopup.SetPanelZIndex(1); }
private UIElement CreateMainScreneTopBar() { // Create Life bar lifeBarGaugeImage = mainScreneImages["life_bar"]; var lifeBarCoverImage = mainScreneImages["character_frame"]; gaugeBarRegion = lifeBarGaugeImage.Region; var lifebarGauge = new ImageElement { Name = "LifeBarBackground", Source = lifeBarGaugeImage, StretchType = StretchType.Fill, }; lifebarGauge.SetGridColumn(1); lifeBarGrid = new Grid(); lifeBarGrid.Children.Add(lifebarGauge); lifeBarGrid.ColumnDefinitions.Add(new StripDefinition(StripType.Fixed, lifeBarCoverImage.Borders.X)); lifeBarGrid.ColumnDefinitions.Add(new StripDefinition(StripType.Star, 0)); lifeBarGrid.ColumnDefinitions.Add(new StripDefinition(StripType.Star, 100)); lifeBarGrid.ColumnDefinitions.Add(new StripDefinition(StripType.Fixed, lifeBarCoverImage.Borders.Y)); lifeBarGrid.RowDefinitions.Add(new StripDefinition()); lifeBarGrid.LayerDefinitions.Add(new StripDefinition()); lifeBarGrid.SetCanvasRelativePosition(new Vector3(0f, 0.185f, 0f)); lifeBarGrid.SetCanvasRelativeSize(new Vector3(1f, 0.25f, 1f)); lifeBarGrid.SetPanelZIndex(-1); var lifebarForeground = new ImageElement { Name = "LifeBarForeGround", Source = lifeBarCoverImage, StretchType = StretchType.Fill, }; lifebarForeground.SetGridColumnSpan(3); lifebarForeground.SetGridRowSpan(3); lifebarForeground.SetCanvasRelativeSize(new Vector3(1f, 1f, 1f)); // Life count lifeCounter = new TextBlock { Text = CreateLifeCountText(), TextColor = Color.Gold, Font = westernFont, TextSize = 32, HorizontalAlignment = HorizontalAlignment.Left }; lifeCounter.SetCanvasAbsolutePosition(new Vector3(lifeBarCoverImage.Borders.X, float.NaN, float.NaN)); lifeCounter.SetCanvasRelativePosition(new Vector3(float.NaN, 0.44f, 0f)); lifeCounter.SetPanelZIndex(1); LifeStatus = 3; // Bonus items var bonusIcon = new ImageElement { Source = mainScreneImages["gold_icon"], Name = "bonus Icon", VerticalAlignment = VerticalAlignment.Center }; bonusCounter = new TextBlock { Text = CreateBonusCountText(), TextColor = Color.White, TextSize = 27, Font = westernFont, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(10, 0, 0, 0) }; // Money var moneyIcon = new ImageElement { Source = mainScreneImages["money_icon"], Name = "money Icon", Margin = new Thickness(20, 0, 0, 0), VerticalAlignment = VerticalAlignment.Center }; moneyCounter = new TextBlock { Text = CreateMoneyCountText(), TextColor = Color.White, TextSize = 27, Font = westernFont, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(10, 0, 0, 0) }; // Stack panel containing the bonus and money counters var moneyBonusStackPanel = new StackPanel { Name = "MoneyBonusStackPanel", Orientation = Orientation.Horizontal, }; moneyBonusStackPanel.Children.Add(bonusIcon); moneyBonusStackPanel.Children.Add(bonusCounter); moneyBonusStackPanel.Children.Add(moneyIcon); moneyBonusStackPanel.Children.Add(moneyCounter); moneyBonusStackPanel.SetCanvasRelativePosition(new Vector3(0.93f, 0.44f, 0f)); moneyBonusStackPanel.SetCanvasRelativeSize(new Vector3(float.NaN, 0.4f, 1f)); moneyBonusStackPanel.SetCanvasPinOrigin(new Vector3(1f, 0f, 0f)); moneyBonusStackPanel.SetPanelZIndex(1); // the main grid of the top bar var mainLayer = new Canvas { VerticalAlignment = VerticalAlignment.Top, MaximumHeight = 150 }; mainLayer.Children.Add(lifeBarGrid); mainLayer.Children.Add(lifebarForeground); mainLayer.Children.Add(lifeCounter); mainLayer.Children.Add(moneyBonusStackPanel); return mainLayer; }
private void SetCurrentContent(StackPanel newContent) { currentStackPanel = newContent; scrollViewer.Content = currentStackPanel; }
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); }
private void AssertCanScroll(StackPanel stackPanel) { for (int i = 0; i < 3; i++) Assert.AreEqual(i==(int)stackPanel.Orientation, stackPanel.CanScroll((Orientation)i)); }
protected override async Task LoadContent() { await base.LoadContent(); var resolution = (Vector3)UIComponent.VirtualResolution; var canvas = new Canvas(); var imgElt = new ImageElement { Name = "UV image", Source = new Sprite(Asset.Load<Texture>("uv")), Width = resolution.X / 5, Height = resolution.Y / 5, StretchType = StretchType.Fill }; imgElt.DependencyProperties.Set(Canvas.PinOriginPropertyKey, 0.5f * Vector3.One); imgElt.DependencyProperties.Set(Canvas.AbsolutePositionPropertyKey, new Vector3(resolution.X / 10, resolution.Y / 10, 0)); imgElt.DependencyProperties.Set(Panel.ZIndexPropertyKey, -1); stackPanel = new StackPanel { Orientation = Orientation.Vertical }; scrollViewer = new ScrollViewer { ScrollMode = ScrollingMode.Vertical }; scrollViewer.DependencyProperties.Set(Canvas.AbsolutePositionPropertyKey, new Vector3(resolution.X / 4, resolution.Y / 10, 0)); scrollViewer.Content = stackPanel; var button1 = new Button { Margin = Thickness.UniformRectangle(5), Padding = Thickness.UniformRectangle(5), LocalMatrix = Matrix.Scaling(2, 2, 2) }; var textOnly = new TextBlock { Text = "Text only button", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15"), TextColor = new Color(1f, 0, 0, 0.5f) }; button1.Content = textOnly; var button2 = new Button { Name = "Button2", Margin = Thickness.UniformRectangle(5), Padding = Thickness.UniformRectangle(5) }; var imageContent = new ImageElement { Name = "Image Button2", Source = new Sprite(Asset.Load<Texture>("uv")), StretchType = StretchType.FillOnStretch, MaximumHeight = 50 }; button2.Content = imageContent; var button3 = new Button { Margin = Thickness.UniformRectangle(5), Padding = Thickness.UniformRectangle(5) }; var stackContent = new StackPanel { Orientation = Orientation.Horizontal }; var stackImage = new ImageElement { Name = "Image stack panel", Source = new Sprite(Asset.Load<Texture>("uv")), MaximumHeight = 50 }; var stackText = new TextBlock { Text = "button text", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15"), Margin = Thickness.UniformRectangle(5) }; stackContent.Children.Add(stackImage); stackContent.Children.Add(stackText); button3.Content = stackContent; var button4 = new Button { Margin = Thickness.UniformRectangle(5), HorizontalAlignment = HorizontalAlignment.Right, Padding = Thickness.UniformRectangle(5) }; var imageContent2 = new ImageElement { Name = "button 4 uv image", Source = new Sprite(Asset.Load<Texture>("uv")), StretchType = StretchType.FillOnStretch, MaximumHeight = 40, Opacity = 0.5f }; button4.Content = imageContent2; var button5 = new Button { Margin = Thickness.UniformRectangle(5), HorizontalAlignment = HorizontalAlignment.Left, Padding = Thickness.UniformRectangle(5) }; var textOnly2 = new TextBlock { Text = "Left aligned", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15") }; button5.Content = textOnly2; var button6 = new ImageButton { Height = 50, Margin = Thickness.UniformRectangle(5), HorizontalAlignment = HorizontalAlignment.Center, PressedImage = new Sprite(Asset.Load<Texture>("ImageButtonPressed")), NotPressedImage = new Sprite(Asset.Load<Texture>("ImageButtonNotPressed")), }; toggle = new ToggleButton { Content = new TextBlock { Text = "Toggle button test", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15") }, IsThreeState = true }; scrollingText = new ScrollingText { Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15"), Text = "<<<--- Scrolling text in a button ", IsEnabled = IsUpdateAutomatic }; var button7 = new Button { Margin = Thickness.UniformRectangle(5), Content = scrollingText }; var uniformGrid = new UniformGrid { Rows = 2, Columns = 2 }; var gridText = new TextBlock { Text = "Uniform grid", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15"), TextAlignment = TextAlignment.Center}; gridText.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 2); var buttonLeft = new Button { Content = new TextBlock { Text = "unif-grid left", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15"), TextAlignment = TextAlignment.Center } }; buttonLeft.DependencyProperties.Set(GridBase.RowPropertyKey, 1); var buttonRight = new Button { Content = new TextBlock { Text = "unif-grid right", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15"), TextAlignment = TextAlignment.Center } }; buttonRight.DependencyProperties.Set(GridBase.RowPropertyKey, 1); buttonRight.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1); uniformGrid.Children.Add(gridText); uniformGrid.Children.Add(buttonLeft); uniformGrid.Children.Add(buttonRight); stackPanel.Children.Add(button1); stackPanel.Children.Add(button2); stackPanel.Children.Add(button3); stackPanel.Children.Add(button4); stackPanel.Children.Add(button5); stackPanel.Children.Add(button6); stackPanel.Children.Add(toggle); stackPanel.Children.Add(button7); stackPanel.Children.Add(uniformGrid); canvas.Children.Add(imgElt); canvas.Children.Add(scrollViewer); UIComponent.RootElement = canvas; }
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 TestItemVirtualizedMeasure() { var measureSize = new Vector3(100, 200, 300); var stackPanel = new StackPanel { ItemVirtualizationEnabled = true, Orientation = Orientation.Vertical }; stackPanel.Children.Add(new UniformGrid { Width = 10, Height = 40 }); stackPanel.Children.Add(new UniformGrid { Width = 20, Height = 30 }); stackPanel.Children.Add(new UniformGrid { Width = 30, Height = 20 }); stackPanel.Measure(measureSize); Assert.AreEqual(new Vector3(30, 90, 0), stackPanel.DesiredSizeWithMargins); }
public void TestScrollOf(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, LayoutingContext = new LayoutingContext() }; 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.ScrollOf(childSize1); Utilities.AssertAreNearlyEqual(1, stackPanel.ScrollPosition); stackPanel.ScrollOf(childSize1); Utilities.AssertAreNearlyEqual(1 + 1 / 3f, stackPanel.ScrollPosition); // post arranged stackPanel.InvalidateArrange(); stackPanel.ScrollOf(childSize1); Utilities.AssertAreNearlyEqual(1 + 1 / 3f, stackPanel.ScrollPosition); stackPanel.Arrange(Vector3.Zero, false); Utilities.AssertAreNearlyEqual(1 + 2 / 3f, stackPanel.ScrollPosition); stackPanel.InvalidateArrange(); stackPanel.ScrollOf(- 2 *childSize1); Utilities.AssertAreNearlyEqual(1 + 2 / 3f, stackPanel.ScrollPosition); stackPanel.Arrange(Vector3.Zero, false); Utilities.AssertAreNearlyEqual(1, 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); }
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); }
private void TestExtent(Orientation direction) { var stackSize = new Vector3(100, 200, 300); var childSize1 = new Vector3(50, 150, 250); var childSize2 = new Vector3(150, 250, 350); var stackPanel = new StackPanel { Size = stackSize, Orientation = direction }; Assert.AreEqual(Vector3.Zero, stackPanel.Extent); var child1 = new StackPanel { Size = childSize1 }; var child2 = new StackPanel { Size = childSize2 }; var child3 = new StackPanel { Size = childSize1 }; stackPanel.Children.Add(child1); stackPanel.Children.Add(child2); stackPanel.Children.Add(child3); stackPanel.Arrange(Vector3.Zero, false); var exactReferenceExtent = stackSize; exactReferenceExtent[(int)direction] = 0; foreach (var child in stackPanel.Children) exactReferenceExtent[(int)direction] += child.Size[(int)direction]; Assert.AreEqual(exactReferenceExtent, stackPanel.Extent); // with virtualized items. stackPanel.ItemVirtualizationEnabled = true; stackPanel.Arrange(Vector3.Zero, false); var childCount = 0; var approximatedSize = 0f; var approximatedReferenceExtent = stackSize; while (childCount < stackPanel.Children.Count-1 && approximatedSize < stackPanel.Size[(int)direction]) { ++childCount; approximatedSize += stackPanel.Children[stackPanel.Children.Count - childCount].Size[(int)direction]; } approximatedReferenceExtent[(int)direction] = stackPanel.Children.Count / (float)childCount * approximatedSize; Assert.AreEqual(approximatedReferenceExtent, stackPanel.Extent); }
private void CreateUI() { VirtualResolution = new Vector3(GraphicsDevice.BackBuffer.Width, GraphicsDevice.BackBuffer.Height, 1); var font = Asset.Load<SpriteFont>("Font"); var canvas = new Canvas(); var stackPanel = new StackPanel { Orientation = Orientation.Vertical, HorizontalAlignment = HorizontalAlignment.Left, MinimumWidth = 200 }; var buttonLightDirect = CreateButton("direct", GetButtonTextOnOff("Direct light: ", directionalLight.Enabled), font, Thickness.UniformRectangle(5)); buttonLightDirect.Click += ToggleLight; var buttonLightPoint = CreateButton("point", GetButtonTextOnOff("Point lights: ", pointLights[0].Enabled), font, Thickness.UniformRectangle(5)); buttonLightPoint.Click += ToggleLight; var buttonLightSpot = CreateButton("spot", GetButtonTextOnOff("Spot light: ", spotLight.Enabled), font, Thickness.UniformRectangle(5)); buttonLightSpot.Click += ToggleLight; buttonShadow = CreateButton("direct", GetButtonTextOnOff("Shadow: ", directionalLight.ShadowMap), font, new Thickness(20, 5, 5, 5)); buttonShadow.Opacity = directionalLight.Enabled ? 1.0f : 0.3f; buttonShadow.CanBeHitByUser = directionalLight.Enabled; buttonShadow.Click += ToggleShadowMap; buttonSpotShadow = CreateButton("spot", GetButtonTextOnOff("Shadow: ", spotLight.ShadowMap), font, new Thickness(20, 5, 5, 5)); buttonSpotShadow.Opacity = spotLight.Enabled ? 1.0f : 0.3f; buttonSpotShadow.CanBeHitByUser = spotLight.Enabled; buttonSpotShadow.Click += ToggleShadowMap; buttonLightRotate = CreateButton("rotate", GetButtonTextOnOff("Lights rotation: ", rotateLights), font, new Thickness(20, 5, 5, 5)); var enabled = pointLights.Count > 0 && pointLights[0].Enabled; buttonLightRotate.Opacity = enabled ? 1.0f : 0.3f; buttonLightRotate.CanBeHitByUser = enabled; buttonLightRotate.Click += ToogleRotation; stackPanel.Children.Add(buttonLightDirect); stackPanel.Children.Add(buttonShadow); stackPanel.Children.Add(buttonLightPoint); stackPanel.Children.Add(buttonLightRotate); stackPanel.Children.Add(buttonLightSpot); stackPanel.Children.Add(buttonSpotShadow); canvas.Children.Add(stackPanel); UI.RootElement = canvas; }
protected override async Task LoadContent() { await base.LoadContent(); var random = new Random(0); var Sprites = Asset.Load<SpriteSheet>("UIImages"); var img1 = new ImageElement { Source = new Sprite(Asset.Load<Texture>("uv")) }; var img2 = new ImageElement { Source = Sprites["GameScreenLeft"] }; var img3 = new ImageElement { Source = Sprites["GameScreenRight"] }; stackPanel1 = new StackPanel { Orientation = Orientation.Vertical, ItemVirtualizationEnabled = true }; stackPanel1.Children.Add(img1); stackPanel1.Children.Add(img2); stackPanel1.Children.Add(img3); stackPanel2 = new StackPanel { Orientation = Orientation.Vertical, ItemVirtualizationEnabled = true }; for (var i = 0; i < 1000; i++) stackPanel2.Children.Add(new Button { Name = "" + i, Height = 75, Content = new TextBlock { Text = "button number " + i, Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15") } }); stackPanel3 = new StackPanel { Orientation = Orientation.Vertical, ItemVirtualizationEnabled = true, VerticalAlignment = VerticalAlignment.Center }; for (var i = 0; i < 103; i++) stackPanel3.Children.Add(new Button { Name = "" + i, Height = 50 + 500 * random.NextFloat(), Content = new TextBlock { Text = "random button number " + i, Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15") } }); stackPanel4 = new StackPanel { Orientation = Orientation.Vertical, ItemVirtualizationEnabled = true }; for (var i = 0; i < 5; i++) stackPanel4.Children.Add(new Button { Name = "" + i, Height = i * 30, Content = new TextBlock { Text = "random button number " + i, Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15") } }); currentStackPanel = stackPanel1; scrollViewer = new ScrollViewer { Name = "sv", Content = currentStackPanel, ScrollMode = ScrollingMode.Vertical }; UIComponent.RootElement = scrollViewer; }
public void TestPropagateEvent() { // create a hierarchy of UIElements // (00) // | // (10) // / \ // (20) (21) // | / \ // (30) (31) (32) var element00 = new ContentControlTest(); var element10 = new StackPanel(); var element20 = new ContentControlTest(); var element21 = new StackPanel(); var element30 = new UIElementLayeringTests(); var element31 = new UIElementLayeringTests(); var element32 = new UIElementLayeringTests(); element00.Content = element10; element10.Children.Add(element20); element10.Children.Add(element21); element20.Content = element30; element21.Children.Add(element31); element21.Children.Add(element32); var elements = new List<UIElement> { element00, element10, element20, element21, element30, element31, element32 }; // create routed events var tunnelingEvent = EventManager.RegisterRoutedEvent<RoutedEventArgs>("TestTuneling", RoutingStrategy.Tunnel, typeof(UIElementLayeringTests)); var bubblingEvent = EventManager.RegisterRoutedEvent<RoutedEventArgs>("TestBubbling", RoutingStrategy.Bubble, typeof(UIElementLayeringTests)); var directEvent = EventManager.RegisterRoutedEvent<RoutedEventArgs>("TestDirect", RoutingStrategy.Direct, typeof(UIElementLayeringTests)); // test propagation direction, propagation bounds and sender values foreach (var uiElement in elements) { uiElement.AddHandler(tunnelingEvent, TestAddSenderToList); uiElement.AddHandler(bubblingEvent, TestAddSenderToList); uiElement.AddHandler(directEvent, TestAddSenderToList); } // tunneling test 1 senderList.Clear(); element20.RaiseEvent(new RoutedEventArgs(tunnelingEvent)); Assert.AreEqual(3, senderList.Count); Assert.AreEqual(element00, senderList[0]); Assert.AreEqual(element10, senderList[1]); Assert.AreEqual(element20, senderList[2]); // tunneling test 2 senderList.Clear(); element31.RaiseEvent(new RoutedEventArgs(tunnelingEvent)); Assert.AreEqual(4, senderList.Count); Assert.AreEqual(element00, senderList[0]); Assert.AreEqual(element10, senderList[1]); Assert.AreEqual(element21, senderList[2]); Assert.AreEqual(element31, senderList[3]); // direct test senderList.Clear(); element10.RaiseEvent(new RoutedEventArgs(directEvent)); Assert.AreEqual(1, senderList.Count); Assert.AreEqual(element10, senderList[0]); // tunneling test 1 senderList.Clear(); element30.RaiseEvent(new RoutedEventArgs(bubblingEvent)); Assert.AreEqual(4, senderList.Count); Assert.AreEqual(element30, senderList[0]); Assert.AreEqual(element20, senderList[1]); Assert.AreEqual(element10, senderList[2]); Assert.AreEqual(element00, senderList[3]); // tunneling test 2 senderList.Clear(); element20.RaiseEvent(new RoutedEventArgs(bubblingEvent)); Assert.AreEqual(3, senderList.Count); Assert.AreEqual(element20, senderList[0]); Assert.AreEqual(element10, senderList[1]); Assert.AreEqual(element00, senderList[2]); // test with another type of handler var eventMyTestHandler = EventManager.RegisterRoutedEvent<MyTestRoutedEventArgs>("TestMyTestHandler", RoutingStrategy.Direct, typeof(UIElementLayeringTests)); AddHandler(eventMyTestHandler, TestMyTestHandler); RaiseEvent(new MyTestRoutedEventArgs(eventMyTestHandler)); Assert.AreEqual(true, testMyTestHandlerCalled); // test Handled and EventHandledToo foreach (var uiElement in elements) { uiElement.RemoveHandler(bubblingEvent, TestAddSenderToList); uiElement.AddHandler(bubblingEvent, TestHandledHandler); } senderList.Clear(); element00.AddHandler(bubblingEvent, TestEventHandledHandler, true); element32.RaiseEvent(new RoutedEventArgs(bubblingEvent)); Assert.AreEqual(1, senderList.Count); Assert.AreEqual(element32, senderList[0]); Assert.AreEqual(true, testEventHandledTooCalled); // test class handlers basic working foreach (var uiElement in elements) uiElement.RemoveHandler(bubblingEvent, TestHandledHandler); EventManager.RegisterClassHandler(typeof(ContentControl), bubblingEvent, TestAddSenderToClassHandlerList); element30.RaiseEvent(new RoutedEventArgs(bubblingEvent)); Assert.AreEqual(2, classHandlerSenderList.Count); Assert.AreEqual(element20, classHandlerSenderList[0]); Assert.AreEqual(element00, classHandlerSenderList[1]); // test that class handlers are called before instance handlers + test handledEventToo for class handlers senderList.Clear(); classHandlerSenderList.Clear(); EventManager.RegisterClassHandler(typeof(ContentControl), bubblingEvent, TestClassHandlerHandled); EventManager.RegisterClassHandler(typeof(StackPanel), bubblingEvent, TestClassHandlerEventHandled, true); foreach (var uiElement in elements) uiElement.AddHandler(bubblingEvent, TestAddSenderToList); element20.RaiseEvent(new RoutedEventArgs(bubblingEvent)); Assert.AreEqual(1, classHandlerSenderList.Count); Assert.AreEqual(element20, classHandlerSenderList[0]); Assert.AreEqual(0, senderList.Count); Assert.AreEqual(true, testClassHandlerEventHandledTooCalled); }
public void TestCanScroll() { var stackPanel = new StackPanel(); stackPanel.Orientation = Orientation.Horizontal; AssertCanScroll(stackPanel); }
public void TestViewport(bool virtualizeChildren) { var random = new Random(); var childSize1 = new Vector3(50, 150, 250); var childSize2 = new Vector3(150, 250, 350); var childSize3 = new Vector3(250, 250, 350); var childSize4 = new Vector3(350, 250, 350); var stackPanel = new StackPanel { DepthAlignment = DepthAlignment.Stretch, ItemVirtualizationEnabled = virtualizeChildren }; Assert.AreEqual(Vector3.Zero, stackPanel.Viewport); var child1 = new StackPanel { Size = childSize1 }; var child2 = new StackPanel { Size = childSize2 }; var child3 = new StackPanel { Size = childSize3 }; var child4 = new StackPanel { Size = childSize4 }; stackPanel.Children.Add(child1); stackPanel.Children.Add(child2); stackPanel.Children.Add(child3); stackPanel.Children.Add(child4); var referencePosition = Vector3.Zero; stackPanel.Arrange(referencePosition, false); Assert.AreEqual(referencePosition, stackPanel.Viewport); referencePosition = random.NextVector3(); stackPanel.Arrange(referencePosition, false); Assert.AreEqual(referencePosition, stackPanel.Viewport); referencePosition = random.NextVector3(); stackPanel.ScrollToEnd(Orientation.Horizontal); stackPanel.ScrollToEnd(Orientation.Vertical); stackPanel.Children.Remove(child4); stackPanel.Arrange(referencePosition, false); Assert.AreEqual(referencePosition, stackPanel.Viewport); var stackSize = new Vector3(100, 200, 300); stackPanel.Size = stackSize; stackPanel.Arrange(Vector3.Zero, false); Assert.AreEqual(stackSize, stackPanel.Viewport); }