protected override Size ArrangeOverride(Size slotSize)
            {
                var child = this.GetChildren().FirstOrDefault();

                if (child != null)
                {
                    var desiredChildSize = LayoutInformation.GetDesiredSize(child);

                    var occludedPadding = ScrollContentPresenter._padding;
                    slotSize.Width  -= occludedPadding.Left + occludedPadding.Right;
                    slotSize.Height -= occludedPadding.Top + occludedPadding.Bottom;

                    var width  = Math.Max(slotSize.Width, desiredChildSize.Width);
                    var height = Math.Max(slotSize.Height, desiredChildSize.Height);

                    ArrangeChild(child, new Rect(
                                     0,
                                     0,
                                     width,
                                     height
                                     ));

                    ScrollContentPresenter.ScrollOwner?.TryApplyPendingScrollTo();

                    // Give opportunity to the the content to define the viewport size itself
                    (child as ICustomScrollInfo)?.ApplyViewport(ref slotSize);
                }

                return(slotSize);
            }
            protected override Size ArrangeOverride(Size slotSize)
            {
                var child = this.GetChildren().FirstOrDefault();

                if (child != null)
                {
                    var desiredChildSize = LayoutInformation.GetDesiredSize(child);

                    var occludedPadding = ScrollContentPresenter._occludedRectPadding;
                    slotSize.Width  -= occludedPadding.Left + occludedPadding.Right;
                    slotSize.Height -= occludedPadding.Top + occludedPadding.Bottom;

                    var width  = Math.Max(slotSize.Width, desiredChildSize.Width);
                    var height = Math.Max(slotSize.Height, desiredChildSize.Height);

                    ArrangeChild(child, new Rect(
                                     0,
                                     0,
                                     width,
                                     height
                                     ));
                }

                return(slotSize);
            }
Esempio n. 3
0
        public void When_UpdateLayout_Then_TreeNotMeasuredUsingCachedValue()
        {
            if (Window.Current.RootElement is Panel root)
            {
                var sut = new Grid
                {
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    VerticalAlignment   = VerticalAlignment.Stretch
                };

                var originalRootAvailableSize = LayoutInformation.GetAvailableSize(root);
                var originalRootDesiredSize   = LayoutInformation.GetDesiredSize(root);
                var originalRootLayoutSlot    = LayoutInformation.GetLayoutSlot(root);

                Size availableSize;
                Rect layoutSlot;
                try
                {
                    LayoutInformation.SetAvailableSize(root, default);
                    LayoutInformation.SetDesiredSize(root, default);
                    LayoutInformation.SetLayoutSlot(root, default);

                    root.Children.Add(sut);
                    sut.UpdateLayout();

                    availableSize = LayoutInformation.GetAvailableSize(sut);
                    layoutSlot    = LayoutInformation.GetLayoutSlot(sut);
                }
                finally
                {
                    LayoutInformation.SetAvailableSize(root, originalRootAvailableSize);
                    LayoutInformation.SetDesiredSize(root, originalRootDesiredSize);
                    LayoutInformation.SetLayoutSlot(root, originalRootLayoutSlot);

                    root.Children.Remove(sut);
                    try { root.UpdateLayout(); }
                    catch { }                     // Make sure to restore visual tree if test has failed!
                }

                Assert.AreNotEqual(default, availableSize);