Example #1
0
        protected override Size MeasureOverride(Size availableSize)
        {
            if (TemplateChild == null)
            {
                return(Size.Zero);
            }

            TemplateChild.Measure(availableSize);
            return(TemplateChild.DesiredSize);
        }
Example #2
0
        protected override Size MeasureOverride(Size availableSize)
        {
            if (TemplateChild == null)
            {
                return(Size.Zero);
            }

            ComputedHorizontalScrollBarVisibility = GetScrollBarVisibility(HorizontalScrollBarVisibility, false);
            ComputedVerticalScrollBarVisibility   = GetScrollBarVisibility(VerticalScrollBarVisibility, false);
            ComputedScrollBarsVisibility          = ComputedHorizontalScrollBarVisibility == Visibility.Visible && ComputedVerticalScrollBarVisibility == Visibility.Visible ? Visibility.Visible : Visibility.Collapsed;

            // 3 passes, each pass can cause an overflow (and add a scrollbar which invalidates the measure), starting with no overlaps
            for (int measurePass = 0; measurePass < 3; measurePass++)
            {
                // computed visibilities can invalidate the ScrollBars measure, invalidate their path so they will be re-measured through TemplateChild
                InvalidateElementMeasurePath(this, HorizontalScrollBar);
                InvalidateElementMeasurePath(this, VerticalScrollBar);

                TemplateChild.Measure(availableSize);

                Visibility measuredHorizontalScrollBarVisibility = GetScrollBarVisibility(HorizontalScrollBarVisibility, scrollContentPresenter != null && scrollContentPresenter.ViewportSize.Width < scrollContentPresenter.ExtentSize.Width);
                Visibility measuredVerticalScrollBarVisibility   = GetScrollBarVisibility(VerticalScrollBarVisibility, scrollContentPresenter != null && scrollContentPresenter.ViewportSize.Height < scrollContentPresenter.ExtentSize.Height);

                if (ComputedHorizontalScrollBarVisibility == measuredHorizontalScrollBarVisibility &&
                    ComputedVerticalScrollBarVisibility == measuredVerticalScrollBarVisibility)
                {
                    break;
                }

                ComputedHorizontalScrollBarVisibility = measuredHorizontalScrollBarVisibility;
                ComputedVerticalScrollBarVisibility   = measuredVerticalScrollBarVisibility;
                ComputedScrollBarsVisibility          = ComputedHorizontalScrollBarVisibility == Visibility.Visible && ComputedVerticalScrollBarVisibility == Visibility.Visible ? Visibility.Visible : Visibility.Collapsed;
            }

            SetScrollInfoSizes();

            return(TemplateChild.DesiredSize);
        }