public void Arrange_Should_Offset_ILogicalScrollable_Bounds_When_Logical_Scroll_Disabled()
        {
            var scrollable = new TestScrollable
            {
                IsLogicalScrollEnabled = false,
            };

            var target = new ScrollContentPresenter
            {
                CanHorizontallyScroll = true,
                CanVerticallyScroll   = true,
                Content = scrollable,
            };

            target.UpdateChild();
            target.Measure(new Size(100, 100));
            target.Arrange(new Rect(0, 0, 100, 100));

            target.Offset = new Vector(25, 25);

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

            Assert.Equal(new Rect(-25, -25, 150, 150), scrollable.Bounds);
        }
        public void Content_Can_Be_Offset()
        {
            Border content;
            var    target = new ScrollContentPresenter
            {
                CanHorizontallyScroll = true,
                CanVerticallyScroll   = true,
                Content = content = new Border
                {
                    Width  = 150,
                    Height = 150,
                },
            };

            target.UpdateChild();
            target.Measure(new Size(100, 100));
            target.Arrange(new Rect(0, 0, 100, 100));

            target.Offset = new Vector(25, 25);

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

            Assert.Equal(new Rect(-25, -25, 150, 150), content.Bounds);
        }
Beispiel #3
0
        public void Changing_Content_Should_Update_State()
        {
            var logicalScrollable = new TestScrollable
            {
                Extent   = new Size(100, 100),
                Offset   = new Vector(50, 50),
                Viewport = new Size(25, 25),
            };

            var nonLogicalScrollable = new TestScrollable
            {
                IsLogicalScrollEnabled = false,
            };

            var target = new ScrollContentPresenter
            {
                CanHorizontallyScroll = true,
                CanVerticallyScroll   = true,
                Content = logicalScrollable,
            };

            target.UpdateChild();
            target.Measure(new Size(100, 100));
            target.Arrange(new Rect(0, 0, 100, 100));

            Assert.Equal(logicalScrollable.Extent, target.Extent);
            Assert.Equal(logicalScrollable.Offset, target.Offset);
            Assert.Equal(logicalScrollable.Viewport, target.Viewport);
            Assert.Equal(new Rect(0, 0, 100, 100), logicalScrollable.Bounds);

            target.Content = nonLogicalScrollable;
            target.UpdateChild();
            target.Measure(new Size(100, 100));
            target.Arrange(new Rect(0, 0, 100, 100));

            Assert.Equal(new Size(150, 150), target.Extent);
            Assert.Equal(new Vector(0, 0), target.Offset);
            Assert.Equal(new Size(100, 100), target.Viewport);
            Assert.Equal(new Rect(0, 0, 150, 150), nonLogicalScrollable.Bounds);

            target.Content = logicalScrollable;
            target.UpdateChild();
            target.Measure(new Size(100, 100));
            target.Arrange(new Rect(0, 0, 100, 100));

            Assert.Equal(logicalScrollable.Extent, target.Extent);
            Assert.Equal(logicalScrollable.Offset, target.Offset);
            Assert.Equal(logicalScrollable.Viewport, target.Viewport);
            Assert.Equal(new Rect(0, 0, 100, 100), logicalScrollable.Bounds);
        }
        public void ScrollOffsetChangesDiscarded_NonScrollable()
        {
            // Offset changes are ignored when the presenter is non-scrollable
            var child = ContentControlWithChild(200, 200);
            ScrollContentPresenter presenter = new ScrollContentPresenter {
                Content = child,
                Width   = 100,
                Height  = 100,
                CanHorizontallyScroll = false,
                CanVerticallyScroll   = false,
                ScrollOwner           = new ScrollViewer()
            };

            presenter.SetHorizontalOffset(50);
            presenter.SetVerticalOffset(50);

            presenter.CanHorizontallyScroll = true;
            presenter.CanVerticallyScroll   = true;

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

            Assert.AreEqual(0, presenter.HorizontalOffset, "#3");
            Assert.AreEqual(0, presenter.VerticalOffset, "#4");
        }
        public void Measure_ExtraSize_SmallerArrange_Scrollable()
        {
            var child     = ContentControlWithChild();
            var presenter = new ScrollContentPresenter {
                CanHorizontallyScroll = true,
                CanVerticallyScroll   = true,
                ScrollOwner           = new ScrollViewer(),
                Content = child
            };

            presenter.Measure(new Size(100, 100));
            presenter.Arrange(new Rect(0, 0, 25, 25));

            Assert.IsTrue(child.IsArranged, "#b");

            Assert.AreEqual(new Size(50, 50), child.ArrangeOverrideArg, "#e");
            Assert.AreEqual(new Size(50, 50), child.ArrangeOverrideArg, "#f");

            Assert.AreEqual(50, presenter.ActualHeight, "#1");
            Assert.AreEqual(50, presenter.ActualWidth, "#2");
            Assert.AreEqual(50, presenter.ExtentHeight, "#3");
            Assert.AreEqual(50, presenter.ExtentWidth, "#4");
            Assert.AreEqual(50, presenter.ViewportHeight, "#5");
            Assert.AreEqual(50, presenter.ViewportWidth, "#6");
            Assert.AreEqual(new Size(50, 50), presenter.RenderSize, "#7");
        }
        public void ScrollContentPresenterContentScrollTest()
        {
            ScrollContentPresenterTestElement content = new ScrollContentPresenterTestElement {
                MeasureSize = new Size(100, 50), ExtentSize = new Size(400, 200)
            };
            ScrollContentPresenter scrollContentPresenter = new ScrollContentPresenter {
                Width = 200, Height = 100, IsRootElement = true
            };

            content.ViewportSize = scrollContentPresenter.RenderSize;

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

            scrollContentPresenter.Content = content;
            Assert.AreEqual(new Size(100, 50), scrollContentPresenter.ExtentSize);

            scrollContentPresenter.CanContentScroll = true;
            Assert.AreEqual(new Size(400, 200), scrollContentPresenter.ExtentSize);
            Assert.AreEqual(new Size(200, 100), content.PreviousAvailableSize);
            Assert.IsFalse(content.CanHorizontallyScroll);
            Assert.IsFalse(content.CanVerticallyScroll);

            scrollContentPresenter.CanHorizontallyScroll = true;
            Assert.AreEqual(new Size(Double.PositiveInfinity, 100), content.PreviousAvailableSize);
            Assert.IsTrue(content.CanHorizontallyScroll);
            Assert.IsFalse(content.CanVerticallyScroll);

            scrollContentPresenter.CanVerticallyScroll = true;
            Assert.AreEqual(new Size(Double.PositiveInfinity, Double.PositiveInfinity), content.PreviousAvailableSize);
            Assert.IsTrue(content.CanHorizontallyScroll);
            Assert.IsTrue(content.CanVerticallyScroll);
        }
        public void MeasureTest_NoOwner()
        {
            var child     = ContentControlWithChild();
            var presenter = new ScrollContentPresenter {
                Content = child
            };

            Assert.AreEqual(0, VisualTreeHelper.GetChildrenCount(presenter));
            presenter.Measure(new Size(100, 100));
            Assert.AreEqual(1, VisualTreeHelper.GetChildrenCount(presenter));
            presenter.Arrange(new Rect(0, 0, 100, 100));

            Assert.IsTrue(child.IsMeasured, "#a");
            Assert.IsTrue(child.IsArranged, "#b");

            Assert.AreEqual(new Size(100, 100), child.MeasureOverrideArg, "#c");
            Assert.AreEqual(new Size(50, 50), child.MeasureOverrideResult, "#d");

            Assert.AreEqual(new Size(100, 100), child.ArrangeOverrideArg, "#e");
            Assert.AreEqual(new Size(100, 100), child.ArrangeOverrideArg, "#f");

            Assert.AreEqual(100, presenter.ActualHeight, "#1");
            Assert.AreEqual(100, presenter.ActualWidth, "#2");
            Assert.AreEqual(0, presenter.ExtentHeight, "#3");
            Assert.AreEqual(0, presenter.ExtentWidth, "#4");
            Assert.AreEqual(0, presenter.ViewportHeight, "#5");
            Assert.AreEqual(0, presenter.ViewportWidth, "#6");
            Assert.AreEqual(new Size(100, 100), presenter.RenderSize, "#7");
        }
        public void Arrange_Should_Constrain_Child_Width_When_CanHorizontallyScroll_False()
        {
            var child = new WrapPanel
            {
                Children =
                {
                    new Border {
                        Width = 40, Height = 50
                    },
                    new Border {
                        Width = 40, Height = 50
                    },
                    new Border {
                        Width = 40, Height = 50
                    },
                }
            };

            var target = new ScrollContentPresenter
            {
                Content = child,
                CanHorizontallyScroll = false,
            };

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

            Assert.Equal(100, child.Bounds.Width);
        }
        public void Alignment_And_Padding_Are_Applied_To_Child_Bounds(
            HorizontalAlignment h,
            VerticalAlignment v,
            double expectedX,
            double expectedY,
            double expectedWidth,
            double expectedHeight)
        {
            Border content;
            var    target = new ScrollContentPresenter
            {
                Padding = new Thickness(10),
                Content = content = new Border
                {
                    MinWidth            = 16,
                    MinHeight           = 16,
                    HorizontalAlignment = h,
                    VerticalAlignment   = v,
                },
            };

            target.UpdateChild();
            target.Measure(new Size(100, 100));
            target.Arrange(new Rect(0, 0, 100, 100));

            Assert.Equal(new Rect(expectedX, expectedY, expectedWidth, expectedHeight), content.Bounds);
        }
        public void Extent_Width_Should_Be_Arrange_Width_When_CanScrollHorizontally_False()
        {
            var child = new WrapPanel
            {
                Children =
                {
                    new Border {
                        Width = 40, Height = 50
                    },
                    new Border {
                        Width = 40, Height = 50
                    },
                    new Border {
                        Width = 40, Height = 50
                    },
                }
            };

            var target = new ScrollContentPresenter
            {
                Content = child,
                CanHorizontallyScroll = false,
            };

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

            Assert.Equal(new Size(100, 100), target.Extent);
        }
        public void BringDescendantIntoView_Should_Handle_Child_Margin()
        {
            Border border;
            var    target = new ScrollContentPresenter
            {
                CanHorizontallyScroll = true,
                CanVerticallyScroll   = true,
                Width   = 100,
                Height  = 100,
                Content = new Decorator
                {
                    Margin = new Thickness(50),
                    Child  = border = new Border
                    {
                        Width  = 200,
                        Height = 200,
                    }
                }
            };

            target.UpdateChild();
            target.Measure(Size.Infinity);
            target.Arrange(new Rect(0, 0, 100, 100));
            target.BringDescendantIntoView(border, new Rect(200, 200, 0, 0));

            Assert.Equal(new Vector(150, 150), target.Offset);
        }
        public void MeasureUpdatesOwner()
        {
            ScrollViewer viewer = new ScrollViewer {
                HorizontalScrollBarVisibility = ScrollBarVisibility.Visible,
                VerticalScrollBarVisibility   = ScrollBarVisibility.Visible
            };

            viewer.Content = ContentControlWithChild();

            TestPanel.Width  = 100;
            TestPanel.Height = 100;
            CreateAsyncTest(viewer, () => {
                ScrollContentPresenter p = Find <ScrollContentPresenter> (viewer, "ScrollContentPresenter");
                Assert.AreEqual(new Size(50, 50), new Size(p.ExtentWidth, p.ExtentHeight), "#1");
                Assert.AreEqual(new Size(73, 73), new Size(p.ViewportWidth, p.ViewportHeight), "#2");
                Assert.AreEqual(new Size(50, 50), new Size(viewer.ExtentWidth, viewer.ExtentHeight), "#3");
                Assert.AreEqual(new Size(73, 73), new Size(viewer.ViewportWidth, viewer.ViewportHeight), "#4");

                p.CanHorizontallyScroll = true;
                p.CanVerticallyScroll   = true;

                p.Measure(new Size(25, 25));

                Assert.AreEqual(new Size(50, 50), new Size(p.ExtentWidth, p.ExtentHeight), "#5");
                Assert.AreEqual(new Size(17, 17), new Size(p.ViewportWidth, p.ViewportHeight), "#6");
                Assert.AreEqual(new Size(50, 50), new Size(viewer.ExtentWidth, viewer.ExtentHeight), "#7");
                Assert.AreEqual(new Size(17, 17), new Size(viewer.ViewportWidth, viewer.ViewportHeight), "#8");
            });
        }
Beispiel #13
0
        public void Toggling_IsLogicalScrollEnabled_Should_Update_State()
        {
            var scrollable = new TestScrollable
            {
                Extent   = new Size(100, 100),
                Offset   = new Vector(50, 50),
                Viewport = new Size(25, 25),
            };

            var target = new ScrollContentPresenter
            {
                CanHorizontallyScroll = true,
                CanVerticallyScroll   = true,
                Content = scrollable,
            };

            target.UpdateChild();
            target.Measure(new Size(100, 100));
            target.Arrange(new Rect(0, 0, 100, 100));

            Assert.Equal(scrollable.Extent, target.Extent);
            Assert.Equal(scrollable.Offset, target.Offset);
            Assert.Equal(scrollable.Viewport, target.Viewport);
            Assert.Equal(new Rect(0, 0, 100, 100), scrollable.Bounds);

            scrollable.IsLogicalScrollEnabled = false;
            scrollable.RaiseScrollInvalidated(EventArgs.Empty);
            target.Measure(new Size(100, 100));
            target.Arrange(new Rect(0, 0, 100, 100));

            Assert.Equal(new Size(150, 150), target.Extent);
            Assert.Equal(new Vector(0, 0), target.Offset);
            Assert.Equal(new Size(100, 100), target.Viewport);
            Assert.Equal(new Rect(0, 0, 150, 150), scrollable.Bounds);

            scrollable.IsLogicalScrollEnabled = true;
            scrollable.RaiseScrollInvalidated(EventArgs.Empty);
            target.Measure(new Size(100, 100));
            target.Arrange(new Rect(0, 0, 100, 100));

            Assert.Equal(scrollable.Extent, target.Extent);
            Assert.Equal(scrollable.Offset, target.Offset);
            Assert.Equal(scrollable.Viewport, target.Viewport);
            Assert.Equal(new Rect(0, 0, 100, 100), scrollable.Bounds);
        }
        public void Measure_Should_Pass_Unchanged_Bounds_To_IScrollable()
        {
            var scrollable = new TestScrollable();
            var target     = new ScrollContentPresenter
            {
                Content = scrollable,
            };

            target.Measure(new Size(100, 100));

            Assert.Equal(new Size(100, 100), scrollable.AvailableSize);
        }
Beispiel #15
0
        public void Measure_Should_Pass_Unbounded_X_If_CanScrollHorizontally()
        {
            var child  = new TestControl();
            var target = new ScrollContentPresenter
            {
                Content = child,
            };

            target.Measure(new Size(100, 100));

            Assert.Equal(Size.Infinity, child.AvailableSize);
        }
Beispiel #16
0
        public void Content_Can_Be_Larger_Than_Viewport()
        {
            TestControl content;
            var         target = new ScrollContentPresenter
            {
                Content = content = new TestControl(),
            };

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

            Assert.Equal(new Rect(0, 0, 150, 150), content.Bounds);
        }
Beispiel #17
0
        public void Measure_Should_Pass_Bounded_X_If_CannotScrollHorizontally()
        {
            var child  = new TestControl();
            var target = new ScrollContentPresenter
            {
                Content = child,
                [ScrollContentPresenter.CanScrollHorizontallyProperty] = false,
            };

            target.Measure(new Size(100, 100));

            Assert.Equal(new Size(100, double.PositiveInfinity), child.AvailableSize);
        }
        public void Measure_Should_Pass_Bounded_X_If_CannotScrollHorizontally()
        {
            var child  = new TestControl();
            var target = new ScrollContentPresenter
            {
                CanVerticallyScroll = true,
                Content             = child,
            };

            target.UpdateChild();
            target.Measure(new Size(100, 100));

            Assert.Equal(new Size(100, double.PositiveInfinity), child.AvailableSize);
        }
        public void Should_Correctly_Arrange_Child_Larger_Than_Viewport()
        {
            var child = new Canvas {
                MinWidth = 150, MinHeight = 150
            };
            var target = new ScrollContentPresenter {
                Content = child,
            };

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

            Assert.Equal(new Size(150, 150), child.Bounds.Size);
        }
        public void Content_Can_Be_Larger_Than_Viewport()
        {
            TestControl content;
            var         target = new ScrollContentPresenter
            {
                CanHorizontallyScroll = true,
                CanVerticallyScroll   = true,
                Content = content = new TestControl(),
            };

            target.UpdateChild();
            target.Measure(new Size(100, 100));
            target.Arrange(new Rect(0, 0, 100, 100));

            Assert.Equal(new Rect(0, 0, 150, 150), content.Bounds);
        }
Beispiel #21
0
        public void Setting_Offset_Should_Invalidate_Arrange()
        {
            var target = new ScrollContentPresenter
            {
                Content = new Border {
                    Width = 140, Height = 150
                }
            };

            target.Measure(new Size(100, 100));
            target.Arrange(new Rect(0, 0, 100, 100));
            target.Offset = new Vector(10, 100);

            Assert.True(target.IsMeasureValid);
            Assert.False(target.IsArrangeValid);
        }
Beispiel #22
0
        public void Content_Can_Be_Stretched()
        {
            Border content;
            var    target = new ScrollContentPresenter
            {
                Content = content = new Border
                {
                    Padding = new Thickness(8),
                },
            };

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

            Assert.Equal(new Rect(0, 0, 100, 100), content.Bounds);
        }
Beispiel #23
0
        public void Content_Can_Be_Right_Aligned()
        {
            Border content;
            var    target = new ScrollContentPresenter
            {
                Content = content = new Border
                {
                    Padding             = new Thickness(8),
                    HorizontalAlignment = HorizontalAlignment.Right
                },
            };

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

            Assert.Equal(new Rect(84, 0, 16, 100), content.Bounds);
        }
Beispiel #24
0
        public void Content_Can_Be_Bottom_Aligned()
        {
            Border content;
            var    target = new ScrollContentPresenter
            {
                Content = content = new Border
                {
                    Padding           = new Thickness(8),
                    VerticalAlignment = VerticalAlignment.Bottom,
                },
            };

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

            Assert.Equal(new Rect(0, 84, 100, 16), content.Bounds);
        }
        public void Arrange_Should_Not_Set_Viewport_And_Extent_With_IScrollable()
        {
            var target = new ScrollContentPresenter
            {
                Content = new TestScrollable()
            };

            var changed = false;

            target.Measure(new Size(100, 100));

            target.GetObservable(ScrollViewer.ViewportProperty).Skip(1).Subscribe(_ => changed = true);
            target.GetObservable(ScrollViewer.ExtentProperty).Skip(1).Subscribe(_ => changed   = true);

            target.Arrange(new Rect(0, 0, 100, 100));

            Assert.False(changed);
        }
        public void DesiredSize_Is_AvailableSize_When_Content_Larger_Than_AvailableSize()
        {
            var target = new ScrollContentPresenter
            {
                Padding = new Thickness(10),
                Content = new Border
                {
                    MinWidth  = 160,
                    MinHeight = 160,
                },
            };

            target.UpdateChild();
            target.Measure(new Size(100, 100));
            target.Arrange(new Rect(0, 0, 100, 100));

            Assert.Equal(new Size(100, 100), target.DesiredSize);
        }
Beispiel #27
0
        public void Content_Can_Be_Offset()
        {
            Border content;
            var    target = new ScrollContentPresenter
            {
                Content = content = new Border
                {
                    Width  = 150,
                    Height = 150,
                },
                Offset = new Vector(25, 25),
            };

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

            Assert.Equal(new Rect(-25, -25, 150, 150), content.Bounds);
        }
        public void Extent_Should_Include_Content_Margin()
        {
            var target = new ScrollContentPresenter
            {
                Content = new Border
                {
                    Width  = 100,
                    Height = 100,
                    Margin = new Thickness(5),
                }
            };

            target.UpdateChild();
            target.Measure(new Size(50, 50));
            target.Arrange(new Rect(0, 0, 50, 50));

            Assert.Equal(new Size(110, 110), target.Extent);
        }
        public void Arrange_Should_Not_Offset_IScrollable_Bounds()
        {
            var scrollable = new TestScrollable
            {
                Extent   = new Size(100, 100),
                Offset   = new Vector(50, 50),
                Viewport = new Size(25, 25),
            };

            var target = new ScrollContentPresenter
            {
                Content = scrollable,
            };

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

            Assert.Equal(new Rect(0, 0, 100, 100), scrollable.Bounds);
        }
        public void BringDescendantIntoView_Should_Update_Offset()
        {
            var target = new ScrollContentPresenter
            {
                Width   = 100,
                Height  = 100,
                Content = new Border
                {
                    Width  = 200,
                    Height = 200,
                }
            };

            target.UpdateChild();
            target.Measure(Size.Infinity);
            target.Arrange(new Rect(0, 0, 100, 100));
            target.BringDescendantIntoView(target.Child, new Rect(200, 200, 0, 0));

            Assert.Equal(new Vector(100, 100), target.Offset);
        }