Пример #1
0
        public void Should_Track_Bounds()
        {
            var target = new BoundsTracker();
            var control = default(Rectangle);
            var tree = new Decorator
            {
                Padding = new Thickness(10),
                Content = new Decorator
                {
                    Padding = new Thickness(5),
                    Content = (control = new Rectangle
                    {
                        Width = 15,
                        Height = 15,
                    }),
                }
            };

            tree.Measure(Size.Infinity);
            tree.Arrange(new Rect(0, 0, 100, 100));

            var track = target.Track(control, tree);
            var results = new List<TransformedBounds>();
            track.Subscribe(results.Add);

            Assert.Equal(new Rect(15, 15, 15, 15), results.Last().Bounds);

            tree.Padding = new Thickness(15);
            tree.Measure(Size.Infinity);
            tree.Arrange(new Rect(0, 0, 100, 100), true);

            Assert.Equal(new Rect(20, 20, 15, 15), results.Last().Bounds);
        }
Пример #2
0
        public void Border_Bottom_Aligns_Content()
        {
            Decorator target = new Decorator
            {
                Padding = new Thickness(8),
                Width = 200,
                Height = 200,
                Child = new Border
                {
                    BorderBrush = Brushes.Black,
                    BorderThickness = 2,
                    Child = new TextBlock
                    {
                        Text = "Foo",
                        Background = Brushes.Red,
                        FontFamily = "Segoe UI",
                        FontSize = 12,
                        VerticalAlignment = VerticalAlignment.Bottom,
                    }
                }
            };

            this.RenderToFile(target);
            this.CompareImages();
        }
Пример #3
0
        public void Polyline_10px_Stroke_PenLineJoin()
        {
            var polylinePoints = new Point[] { new Point(0, 0), new Point(5, 0), new Point(6, -2), new Point(7, 3), new Point(8, -3),
                new Point(9, 1), new Point(10, 0), new Point(15, 0) };

            Decorator target = new Decorator
            {
                Padding = new Thickness(8),
                Width = 400,
                Height = 200,
                Child = new Polyline
                {
                    Stroke = Brushes.Brown,
                    Points = polylinePoints,
                    Stretch = Stretch.Uniform,
                    StrokeJoin = PenLineJoin.Round,
                    StrokeStartLineCap = PenLineCap.Round,
                    StrokeEndLineCap = PenLineCap.Round,
                    StrokeThickness = 10
                }
            };

            RenderToFile(target);
            CompareImages();
        }
Пример #4
0
        public void LinearGradientBrush_RedBlue_Vertical_Fill()
        {
            Decorator target = new Decorator
            {
                Padding = new Thickness(8),
                Width = 200,
                Height = 200,
                Child = new Border
                {
                    Background = new LinearGradientBrush
                    {
                        StartPoint = new RelativePoint(0.5, 0, RelativeUnit.Relative),
                        EndPoint = new RelativePoint(0.5, 1, RelativeUnit.Relative),
                        GradientStops =
                        {
                            new GradientStop { Color = Colors.Red, Offset = 0 },
                            new GradientStop { Color = Colors.Blue, Offset = 1 }
                        }
                    }
                }
            };

            RenderToFile(target);
            CompareImages();
        }
Пример #5
0
        public void Path_Expander_With_Border()
        {
            Decorator target = new Decorator
            {
                Width = 200,
                Height = 200,
                Child = new Border
                {
                    BorderBrush = Brushes.Red,
                    BorderThickness = 1,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment = VerticalAlignment.Center,
                    Child = new Path
                    {
                        Fill = Brushes.Black,
                        Stroke = Brushes.Black,
                        StrokeThickness = 1,
                        Stretch = Stretch.Uniform,
                        Data = StreamGeometry.Parse("M 0 2 L 4 6 L 0 10 Z"),
                    }
                }
            };

            this.RenderToFile(target);
            this.CompareImages();
        }
Пример #6
0
        public void Border_Fill()
        {
            Decorator target = new Decorator
            {
                Padding = new Thickness(8),
                Width = 200,
                Height = 200,
                Child = new Border
                {
                    Background = Brushes.Red,
                }
            };

            RenderToFile(target);
            CompareImages();
        }
Пример #7
0
        public void Circle_1px_Stroke()
        {
            Decorator target = new Decorator
            {
                Padding = new Thickness(8),
                Width = 200,
                Height = 200,
                Child = new Ellipse
                {
                    Stroke = Brushes.Black,
                    StrokeThickness = 1,
                }
            };

            this.RenderToFile(target);
            this.CompareImages();
        }
Пример #8
0
        public void Border_1px_Border()
        {
            Decorator target = new Decorator
            {
                Padding = new Thickness(8),
                Width = 200,
                Height = 200,
                Content = new Border
                {
                    BorderBrush = Brushes.Black,
                    BorderThickness = 1,
                }
            };

            this.RenderToFile(target);
            this.CompareImages();
        }
Пример #9
0
        public void Rectangle_1px_Stroke()
        {
            Decorator target = new Decorator
            {
                Padding = new Thickness(8),
                Width = 200,
                Height = 200,
                Content = new Rectangle
                {
                    Stroke = Brushes.Black,
                    StrokeThickness = 1,
                }
            };

            this.RenderToFile(target);
            this.CompareImages();
        }
Пример #10
0
        public void Border_2px_Border()
        {
            Decorator target = new Decorator
            {
                Padding = new Thickness(8),
                Width = 200,
                Height = 200,
                Child = new Border
                {
                    BorderBrush = Brushes.Black,
                    BorderThickness = 2,
                }
            };

            RenderToFile(target);
            CompareImages();
        }
Пример #11
0
        public void Rectangle_2px_Stroke()
        {
            Decorator target = new Decorator
            {
                Padding = new Thickness(8),
                Width = 200,
                Height = 200,
                Child = new Rectangle
                {
                    Stroke = Brushes.Black,
                    StrokeThickness = 2,
                }
            };

            RenderToFile(target);
            CompareImages();
        }
Пример #12
0
        public void Negative_Margin_Larger_Than_Constraint_Should_Request_Height_0()
        {
            Control target;

            var outer = new Decorator
            {
                Width = 100,
                Height = 100,
                Child = target = new Control
                {
                    Margin = new Thickness(0, -100, 0, 0),
                }
            };

            outer.Measure(Size.Infinity);

            Assert.Equal(0, target.DesiredSize.Height);
        }
Пример #13
0
        public void Line_1px_Stroke_Vertical()
        {
            Decorator target = new Decorator
            {
                Width = 200,
                Height = 200,
                Child = new Line
                {
                    Stroke = Brushes.Black,
                    StrokeThickness = 1,
                    StartPoint = new Point(100, 200),
                    EndPoint = new Point(100, 0)
                }
            };

            RenderToFile(target);
            CompareImages();
        }
Пример #14
0
        public void Tapped_Should_Be_Raised_Even_When_PointerPressed_Handled()
        {
            Border border;
            var decorator = new Decorator
            {
                Child = border = new Border()
            };
            var result = new List<string>();

            border.AddHandler(Border.PointerPressedEvent, (s, e) => e.Handled = true);
            decorator.AddHandler(Gestures.TappedEvent, (s, e) => result.Add("dt"));
            border.AddHandler(Gestures.TappedEvent, (s, e) => result.Add("bt"));

            border.RaiseEvent(new PointerPressedEventArgs());
            border.RaiseEvent(new PointerReleasedEventArgs());

            Assert.Equal(new[] { "bt", "dt" }, result);
        }
Пример #15
0
        public void Polygon_NonUniformFill()
        {
            Decorator target = new Decorator
            {
                Padding = new Thickness(8),
                Width = 400,
                Height = 200,
                Child = new Polygon
                {
                    Stroke = Brushes.DarkBlue,
                    Stretch = Stretch.Fill,
                    Fill = Brushes.Violet,
                    Points = new[] { new Point(5, 0), new Point(8, 8), new Point(0, 3), new Point(10, 3), new Point(2, 8) },
                    StrokeThickness = 5,
                }
            };

            RenderToFile(target);
            CompareImages();
        }
Пример #16
0
        public void Path_100px_Triangle_Centered()
        {
            Decorator target = new Decorator
            {
                Width = 200,
                Height = 200,
                Child = new Path
                {
                    Fill = Brushes.Gray,
                    Stroke = Brushes.Red,
                    StrokeThickness = 2,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment = VerticalAlignment.Center,
                    Data = StreamGeometry.Parse("M 0,100 L 100,100 50,0 Z"),
                }
            };

            this.RenderToFile(target);
            this.CompareImages();
        }
Пример #17
0
        public void Image_Stretch_None()
        {
            Decorator target = new Decorator
            {
                Padding = new Thickness(20, 8),
                Width = 200,
                Height = 200,
                Content = new Border
                {
                    Background = Brushes.Red,
                    Content = new Image
                    {
                        Source = this.bitmap,
                        Stretch = Stretch.None,
                    }
                }
            };

            this.RenderToFile(target);
            this.CompareImages();
        }
Пример #18
0
        public void Image_Stretch_Fill()
        {
            Decorator target = new Decorator
            {
                Padding = new Thickness(20, 8),
                Width = 200,
                Height = 200,
                Child = new Border
                {
                    Background = Brushes.Red,
                    Child = new Image
                    {
                        Source = _bitmap,
                        Stretch = Stretch.Fill,
                    }
                }
            };

            RenderToFile(target);
            CompareImages();
        }
Пример #19
0
        public void Path_Tick_Scaled()
        {
            Decorator target = new Decorator
            {
                Width = 200,
                Height = 200,
                Child = new Path
                {
                    Fill = Brushes.Gray,
                    Stroke = Brushes.Red,
                    StrokeThickness = 2,
                    Stretch = Stretch.Uniform,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment = VerticalAlignment.Center,
                    Data = StreamGeometry.Parse("M 1145.607177734375,430 C1145.607177734375,430 1141.449951171875,435.0772705078125 1141.449951171875,435.0772705078125 1141.449951171875,435.0772705078125 1139.232177734375,433.0999755859375 1139.232177734375,433.0999755859375 1139.232177734375,433.0999755859375 1138,434.5538330078125 1138,434.5538330078125 1138,434.5538330078125 1141.482177734375,438 1141.482177734375,438 1141.482177734375,438 1141.96875,437.9375 1141.96875,437.9375 1141.96875,437.9375 1147,431.34619140625 1147,431.34619140625 1147,431.34619140625 1145.607177734375,430 1145.607177734375,430 z"),
                }
            };

            RenderToFile(target);
            CompareImages();
        }
Пример #20
0
        public void InputHitTest_Should_Not_Find_Control_Outside_Point()
        {
            var container = new Decorator
            {
                Width = 200,
                Height = 200,
                Child = new Border
                {
                    Width = 100,
                    Height = 100,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment = VerticalAlignment.Center
                }
            };

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

            var result = container.InputHitTest(new Point(10, 10));

            Assert.Equal(container, result);
        }
Пример #21
0
        public void ImageBrush_NoStretch_NoTile_Alignment_Center()
        {
            Decorator target = new Decorator
            {
                Padding = new Thickness(8),
                Width = 200,
                Height = 200,
                Child = new Rectangle
                {
                    Fill = new ImageBrush
                    {
                        Stretch = Stretch.None,
                        TileMode = TileMode.None,
                        AlignmentX = AlignmentX.Center,
                        AlignmentY = AlignmentY.Center,
                        Source = new Bitmap(BitmapPath),
                    }
                }
            };

            RenderToFile(target);
            CompareImages();
        }
Пример #22
0
        public void VisualBrush_NoStretch_NoTile_Alignment_TopLeft()
        {
            Decorator target = new Decorator
            {
                Padding = new Thickness(8),
                Width = 200,
                Height = 200,
                Child = new Rectangle
                {
                    Fill = new VisualBrush
                    {
                        Stretch = Stretch.None,
                        TileMode = TileMode.None,
                        AlignmentX = AlignmentX.Left,
                        AlignmentY = AlignmentY.Top,
                        Visual = Visual,
                    }
                }
            };

            RenderToFile(target);
            CompareImages();
        }
Пример #23
0
        public void VisualBrush_Align_TopLeft()
        {
            Decorator target = new Decorator
            {
                Padding = new Thickness(8),
                Width = 200,
                Height = 200,
                Child = new Rectangle
                {
                    Fill = new VisualBrush
                    {
                        AlignmentX = AlignmentX.Left,
                        AlignmentY = AlignmentY.Top,
                        Stretch = Stretch.None,
                        Visual = new Border
                        {
                            Width = 92,
                            Height = 92,
                            Background = Brushes.Red,
                            BorderBrush = Brushes.Black,
                            BorderThickness = 2,
                            Child = new TextBlock
                            {
                                Text = "Perspex",
                                FontSize = 12,
                                FontFamily = "Arial",
                                HorizontalAlignment = HorizontalAlignment.Center,
                                VerticalAlignment = VerticalAlignment.Center,
                            }
                        }
                    }
                }
            };

            RenderToFile(target);
            CompareImages();
        }
Пример #24
0
        public void DoubleTapped_Should_Follow_Pointer_Pressed_Released_Pressed()
        {
            Border border;
            var decorator = new Decorator
            {
                Child = border = new Border()
            };
            var result = new List<string>();

            decorator.AddHandler(Border.PointerPressedEvent, (s, e) => result.Add("dp"));
            decorator.AddHandler(Border.PointerReleasedEvent, (s, e) => result.Add("dr"));
            decorator.AddHandler(Gestures.TappedEvent, (s, e) => result.Add("dt"));
            decorator.AddHandler(Gestures.DoubleTappedEvent, (s, e) => result.Add("ddt"));
            border.AddHandler(Border.PointerPressedEvent, (s, e) => result.Add("bp"));
            border.AddHandler(Border.PointerReleasedEvent, (s, e) => result.Add("br"));
            border.AddHandler(Gestures.TappedEvent, (s, e) => result.Add("bt"));
            border.AddHandler(Gestures.DoubleTappedEvent, (s, e) => result.Add("bdt"));

            border.RaiseEvent(new PointerPressedEventArgs());
            border.RaiseEvent(new PointerReleasedEventArgs());
            border.RaiseEvent(new PointerPressedEventArgs { ClickCount = 2 });

            Assert.Equal(new[] { "bp", "dp", "br", "dr", "bt", "dt", "bp", "dp", "bdt", "ddt" }, result);
        }
Пример #25
0
        public void Rectangle_Stroke_Fill_ClipToBounds()
        {
            Decorator target = new Decorator
            {
                Padding = new Thickness(8),
                Width = 200,
                Height = 200,
                Child = new Rectangle
                {
                    Stroke = Brushes.Black,
                    StrokeThickness = 2,
                    Fill = Brushes.Red,
                    ClipToBounds = true,
                }
            };

            RenderToFile(target);
            CompareImages();
        }
        public void Up_Continue_Returns_Parent()
        {
            Button current;

            var top = new Decorator
            {
                Focusable = true,
                [KeyboardNavigation.DirectionalNavigationProperty] = KeyboardNavigationMode.Continue,
                Child = current = new Button
                {
                    Name = "Button",
                }
            };

            var result = KeyboardNavigationHandler.GetNext(current, FocusNavigationDirection.Up);

            Assert.Equal(top, result);
        }
        public void Up_Contained_Doesnt_Return_Child_Control()
        {
            Decorator current;

            var top = new StackPanel
            {
                [KeyboardNavigation.DirectionalNavigationProperty] = KeyboardNavigationMode.Contained,
                Children = new Controls
                {
                    (current = new Decorator
                    {
                        Focusable = true,
                        Child = new Button(),
                    })
                }
            };

            var result = KeyboardNavigationHandler.GetNext(current, FocusNavigationDirection.Up);

            Assert.Null(result);
        }
        public void Previous_Continue_Returns_Parent()
        {
            Button current;

            var top = new Decorator
            {
                Focusable = true,
                Child = current = new Button
                {
                    Name = "Button",
                }
            };

            var result = KeyboardNavigationHandler.GetNext(current, FocusNavigationDirection.Previous);

            Assert.Equal(top, result);
        }
Пример #29
0
        public void DataContext_Binding_Should_Use_Parent_DataContext()
        {
            var parentDataContext = Mock.Of<IHeadered>(x => x.Header == (object)"Foo");

            var parent = new Decorator
            {
                Child = new Control(),
                DataContext = parentDataContext,
            };

            var binding = new Binding
            {
                Path = "Header",
            };

            binding.Bind(parent.Child, Control.DataContextProperty);

            Assert.Equal("Foo", parent.Child.DataContext);

            parentDataContext = Mock.Of<IHeadered>(x => x.Header == (object)"Bar");
            parent.DataContext = parentDataContext;
            Assert.Equal("Bar", parent.Child.DataContext);
        }
Пример #30
0
        public void DataContext_Binding_Should_Track_Parent()
        {
            var parent = new Decorator
            {
                DataContext = new { Foo = "foo" },
            };

            var child = new Control();

            var binding = new Binding
            {
                Path = "Foo",
            };

            binding.Bind(child, Control.DataContextProperty);
            Assert.Null(child.DataContext);
            parent.Child = child;
            Assert.Equal("foo", child.DataContext);
        }