Exemplo n.º 1
0
        public void TestSurroudingAnchor()
        {
            var childSize1 = new Vector3(50, 150, 250);
            var childSize2 = new Vector3(100, 200, 300);

            var grid = new Grid { VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center };
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Fixed, 100));
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Fixed, 200));
            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto));
            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto));
            grid.LayerDefinitions.Add(new StripDefinition(StripType.Star));
            grid.LayerDefinitions.Add(new StripDefinition(StripType.Star));

            var child1 = new UniformGrid { Size = childSize1 };
            var child2 = new UniformGrid { Size = childSize2 };
            child2.DependencyProperties.Set(GridBase.RowPropertyKey, 1);

            grid.Children.Add(child1);
            grid.Children.Add(child2);

            grid.Measure(1000 * Vector3.One);
            grid.Arrange(1000 * Vector3.One, false);
            
            Assert.AreEqual(new Vector2(   0, 100), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, -1));
            Assert.AreEqual(new Vector2(   0, 100), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, 0));
            Assert.AreEqual(new Vector2( -50,  50), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, 50));
            Assert.AreEqual(new Vector2( -80,  20), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, 80));
            Assert.AreEqual(new Vector2(   0, 200), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, 100));
            Assert.AreEqual(new Vector2( -10, 190), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, 110));
            Assert.AreEqual(new Vector2(-200,   0), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, 300));
            Assert.AreEqual(new Vector2(-200,   0), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, 500));
            
            Assert.AreEqual(new Vector2(   0, 150), grid.GetSurroudingAnchorDistances(Orientation.Vertical, -1));
            Assert.AreEqual(new Vector2(   0, 150), grid.GetSurroudingAnchorDistances(Orientation.Vertical, 0));
            Assert.AreEqual(new Vector2( -50, 100), grid.GetSurroudingAnchorDistances(Orientation.Vertical, 50));
            Assert.AreEqual(new Vector2( -80,  70), grid.GetSurroudingAnchorDistances(Orientation.Vertical, 80));
            Assert.AreEqual(new Vector2(   0, 200), grid.GetSurroudingAnchorDistances(Orientation.Vertical, 150));
            Assert.AreEqual(new Vector2( -10, 190), grid.GetSurroudingAnchorDistances(Orientation.Vertical, 160));
            Assert.AreEqual(new Vector2(-200,   0), grid.GetSurroudingAnchorDistances(Orientation.Vertical, 350));
            Assert.AreEqual(new Vector2(-200,   0), grid.GetSurroudingAnchorDistances(Orientation.Vertical, 500));
            
            Assert.AreEqual(new Vector2(   0, 300), grid.GetSurroudingAnchorDistances(Orientation.InDepth, -1));
            Assert.AreEqual(new Vector2(   0, 300), grid.GetSurroudingAnchorDistances(Orientation.InDepth, 0));
            Assert.AreEqual(new Vector2( -50, 250), grid.GetSurroudingAnchorDistances(Orientation.InDepth, 50));
            Assert.AreEqual(new Vector2( -80, 220), grid.GetSurroudingAnchorDistances(Orientation.InDepth, 80));
            Assert.AreEqual(new Vector2(   0, 300), grid.GetSurroudingAnchorDistances(Orientation.InDepth, 300));
            Assert.AreEqual(new Vector2( -10, 290), grid.GetSurroudingAnchorDistances(Orientation.InDepth, 310));
            Assert.AreEqual(new Vector2(-300,   0), grid.GetSurroudingAnchorDistances(Orientation.InDepth, 600));
            Assert.AreEqual(new Vector2(-300,   0), grid.GetSurroudingAnchorDistances(Orientation.InDepth, 900));
        }