Esempio n. 1
0
        public void Should_Track_Bounds()
        {
            var target  = new BoundsTracker();
            var control = default(Rectangle);
            var tree    = new Decorator
            {
                Padding = new Thickness(10),
                Child   = new Decorator
                {
                    Padding = new Thickness(5),
                    Child   = 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);
        }
Esempio n. 2
0
        public void Should_Track_Bounds()
        {
            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                var control = default(Rectangle);
                var tree    = new Decorator
                {
                    Padding = new Thickness(10),
                    Child   = new Decorator
                    {
                        Padding = new Thickness(5),
                        Child   = control = new Rectangle
                        {
                            Width  = 15,
                            Height = 15,
                        },
                    }
                };

                var context = new DrawingContext(Mock.Of <IDrawingContextImpl>());

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

                var track   = control.GetObservable(Visual.TransformedBoundsProperty);
                var results = new List <TransformedBounds?>();
                track.Subscribe(results.Add);

                Assert.Equal(new Rect(0, 0, 15, 15), results[0].Value.Bounds);
                Assert.Equal(Matrix.CreateTranslation(42, 42), results[0].Value.Transform);
            }
        }
Esempio n. 3
0
        public void GetVisualsAt_Should_Not_Find_Control_Outside_Point()
        {
            using (UnitTestApplication.Start(new TestServices(renderInterface: new MockRenderInterface())))
            {
                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 context = new DrawingContext(Mock.Of <IDrawingContextImpl>());
                context.Render(container);

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

                Assert.Equal(new[] { container }, result);
            }
        }
Esempio n. 4
0
            protected override Size ArrangeOverride(Size finalSize)
            {
                Popup p = AdornedElement as Popup;

                if (p != null)
                {
                    FrameworkElement element = p.Child as FrameworkElement;
                    Point            loc     = element.TranslatePoint(new Point(), p);
                    loc.Y += element.Margin.Top;
                    if (PlacementMode == PlacementMode.Left)
                    {
                        loc.X += element.ActualWidth - element.Margin.Right;
                    }
                    _decorator.Arrange(new Rect(loc, finalSize));
                }
                else
                {
                    _decorator.Arrange(new Rect(new Point(), finalSize));
                }
                return(finalSize);
            }
Esempio n. 5
0
        public void Bounds_Should_Not_Include_Margin()
        {
            var target = new Decorator
            {
                Width  = 100,
                Height = 100,
                Margin = new Thickness(5),
            };

            Assert.False(target.IsMeasureValid);
            target.Measure(Size.Infinity);
            target.Arrange(new Rect(target.DesiredSize));
            Assert.Equal(new Rect(5, 5, 100, 100), target.Bounds);
        }
Esempio n. 6
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);
        }
Esempio n. 7
0
        public void KeyboardDirectionalNavigationTransformTest()
        {
            Control child1 = new Control {
                Name = "child1", Width = 100, Height = 100, RenderTransform = new TranslateTransform(-300, 200)
            };
            Control child2 = new Control {
                Name = "child2", Width = 100, Height = 100, RenderTransform = new TranslateTransform(-290, -200)
            };
            Control child3 = new Control {
                Name = "child3", Width = 100, Height = 100, RenderTransform = new TranslateTransform(-100, 0)
            };
            Control child4 = new Control {
                Name = "child4", Width = 100, Height = 100, RenderTransform = new TranslateTransform(100, 190)
            };
            Control child5 = new Control {
                Name = "child5", Width = 100, Height = 100, RenderTransform = new TranslateTransform(110, -210)
            };

            Grid grid = new Grid
            {
                Margin          = new Thickness(100, 200, 0, 0),
                RenderTransform = new RotateTransform {
                    Angle = 90
                }
            };

            grid.Children.Add(child1);
            grid.Children.Add(child2);
            grid.Children.Add(child3);
            grid.Children.Add(child4);
            grid.Children.Add(child5);

            Decorator root = new Decorator
            {
                IsRootElement = true,
                Child         = grid,
                Margin        = new Thickness(200, 100, 0, 0),
            };

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

            KeyboardNavigation.SetDirectionalNavigation(root, KeyboardNavigationMode.Contained);

            Assert.AreEqual(child1, KeyboardNavigationTarget.FindTarget(child1, FocusNavigationDirection.Left, KeyboardNavigation.DirectionalNavigationProperty));
            Assert.AreEqual(child3, KeyboardNavigationTarget.FindTarget(child1, FocusNavigationDirection.Right, KeyboardNavigation.DirectionalNavigationProperty));
            Assert.AreEqual(child1, KeyboardNavigationTarget.FindTarget(child1, FocusNavigationDirection.Up, KeyboardNavigation.DirectionalNavigationProperty));
            Assert.AreEqual(child3, KeyboardNavigationTarget.FindTarget(child1, FocusNavigationDirection.Down, KeyboardNavigation.DirectionalNavigationProperty));

            Assert.AreEqual(child3, KeyboardNavigationTarget.FindTarget(child2, FocusNavigationDirection.Left, KeyboardNavigation.DirectionalNavigationProperty));
            Assert.AreEqual(child2, KeyboardNavigationTarget.FindTarget(child2, FocusNavigationDirection.Right, KeyboardNavigation.DirectionalNavigationProperty));
            Assert.AreEqual(child2, KeyboardNavigationTarget.FindTarget(child2, FocusNavigationDirection.Up, KeyboardNavigation.DirectionalNavigationProperty));
            Assert.AreEqual(child3, KeyboardNavigationTarget.FindTarget(child2, FocusNavigationDirection.Down, KeyboardNavigation.DirectionalNavigationProperty));

            Assert.AreEqual(child4, KeyboardNavigationTarget.FindTarget(child3, FocusNavigationDirection.Left, KeyboardNavigation.DirectionalNavigationProperty));
            Assert.AreEqual(child2, KeyboardNavigationTarget.FindTarget(child3, FocusNavigationDirection.Right, KeyboardNavigation.DirectionalNavigationProperty));
            Assert.AreEqual(child2, KeyboardNavigationTarget.FindTarget(child3, FocusNavigationDirection.Up, KeyboardNavigation.DirectionalNavigationProperty));
            Assert.AreEqual(child4, KeyboardNavigationTarget.FindTarget(child3, FocusNavigationDirection.Down, KeyboardNavigation.DirectionalNavigationProperty));

            Assert.AreEqual(child4, KeyboardNavigationTarget.FindTarget(child4, FocusNavigationDirection.Left, KeyboardNavigation.DirectionalNavigationProperty));
            Assert.AreEqual(child3, KeyboardNavigationTarget.FindTarget(child4, FocusNavigationDirection.Right, KeyboardNavigation.DirectionalNavigationProperty));
            Assert.AreEqual(child3, KeyboardNavigationTarget.FindTarget(child4, FocusNavigationDirection.Up, KeyboardNavigation.DirectionalNavigationProperty));
            Assert.AreEqual(child4, KeyboardNavigationTarget.FindTarget(child4, FocusNavigationDirection.Down, KeyboardNavigation.DirectionalNavigationProperty));

            Assert.AreEqual(child3, KeyboardNavigationTarget.FindTarget(child5, FocusNavigationDirection.Left, KeyboardNavigation.DirectionalNavigationProperty));
            Assert.AreEqual(child5, KeyboardNavigationTarget.FindTarget(child5, FocusNavigationDirection.Right, KeyboardNavigation.DirectionalNavigationProperty));
            Assert.AreEqual(child3, KeyboardNavigationTarget.FindTarget(child5, FocusNavigationDirection.Up, KeyboardNavigation.DirectionalNavigationProperty));
            Assert.AreEqual(child5, KeyboardNavigationTarget.FindTarget(child5, FocusNavigationDirection.Down, KeyboardNavigation.DirectionalNavigationProperty));
        }
Esempio n. 8
0
 protected override Size ArrangeOverride(Size arrangeSize)
 {
     _transformDecorator.Arrange(new Rect(arrangeSize));
     return(arrangeSize);
 }
Esempio n. 9
0
 protected override Size ArrangeOverride(Size finalSize)
 {
     decorator.Arrange(new Rect(new Point(), finalSize));
     return(finalSize);
 }