Exemple #1
0
        public void BorderRenderTest()
        {
            Brush backgroundBrush = new LinearGradientBrush(30, Colors.Blue, Colors.Green);
            Brush borderBrush = new LinearGradientBrush(-30, Colors.Red, Colors.Blue);
            Thickness borderThickness = new Thickness(10, 20, 30, 40);

            Border border = new Border
            {
                Child = new FrameworkElement { Width = 200, Height = 100 },
                Background = backgroundBrush,
                BorderBrush = borderBrush,
                BorderThickness = borderThickness,
            };

            border.Measure(Size.Infinity);
            border.Arrange(new Rect(border.DesiredSize));

            IRenderElementFactory factory = TestRenderElementFactory.Default;

            border.GetRenderElement(factory);

            Assert.AreEqual(new Rect(240, 160), border.GetRenderElement(factory).Bounds);

            Assert.AreEqual(2, border.GetRenderElement(factory).Children.Count());

            IBorderRenderElement borderRenderElement = border.GetRenderElement(factory).Children.ElementAt(0) as IBorderRenderElement;
            Assert.IsNotNull(borderRenderElement);
            Assert.AreEqual(backgroundBrush, borderRenderElement.Background);
            Assert.AreEqual(borderBrush, borderRenderElement.BorderBrush);
            Assert.AreEqual(borderThickness, borderRenderElement.BorderThickness);
            Assert.AreEqual(new Rect(240, 160), borderRenderElement.Bounds);

            IVisualRenderElement visualRenderElement = border.GetRenderElement(factory).Children.ElementAt(1) as IVisualRenderElement;
            Assert.IsNotNull(visualRenderElement);
            Assert.AreEqual(new Rect(10, 20, 200, 100), visualRenderElement.Bounds);

            border.Child = null;
            Assert.AreEqual(1, border.GetRenderElement(factory).Children.Count());
        }