Ejemplo n.º 1
0
        public static Size ComputeDesiredSize(this IFrameworkElement frameworkElement, double widthConstraint, double heightConstraint)
        {
            _ = frameworkElement ?? throw new ArgumentNullException(nameof(frameworkElement));

            if (frameworkElement.Handler == null)
            {
                return(Size.Zero);
            }

            var margin = frameworkElement.GetMargin();

            // Adjust the constraints to account for the margins
            widthConstraint  -= margin.HorizontalThickness;
            heightConstraint -= margin.VerticalThickness;

            // Determine whether the external constraints or the requested size values will determine the measurements
            widthConstraint  = LayoutManager.ResolveConstraints(widthConstraint, frameworkElement.Width);
            heightConstraint = LayoutManager.ResolveConstraints(heightConstraint, frameworkElement.Height);

            // Ask the handler to do the actual measuring
            var measureWithMargins = frameworkElement.Handler.GetDesiredSize(widthConstraint, heightConstraint);

            // Account for the margins when reporting the desired size value
            return(new Size(measureWithMargins.Width + margin.HorizontalThickness,
                            measureWithMargins.Height + margin.VerticalThickness));
        }
Ejemplo n.º 2
0
        public Size Measure(double widthConstraint, double heightConstraint)
        {
            double width  = 0;
            double height = 0;

            if (!double.IsInfinity(widthConstraint))
            {
                width = widthConstraint;
            }

            if (!double.IsInfinity(heightConstraint))
            {
                height = heightConstraint;
            }

            height = LayoutManager.ResolveConstraints(height, FlexLayout.Height, height, FlexLayout.MinimumHeight, FlexLayout.MaximumHeight);
            width  = LayoutManager.ResolveConstraints(width, FlexLayout.Width, width, FlexLayout.MinimumWidth, FlexLayout.MaximumWidth);

            return(new Size(width, height));
        }
Ejemplo n.º 3
0
        public Size Measure(double widthConstraint, double heightConstraint)
        {
            double measuredHeight = 0;
            double measuredWidth  = 0;

            FlexLayout.Layout(widthConstraint, heightConstraint);

            foreach (var child in FlexLayout)
            {
                if (child.Visibility == Visibility.Collapsed)
                {
                    continue;
                }

                var frame = FlexLayout.GetFlexFrame(child);
                measuredHeight = Math.Max(measuredHeight, frame.Bottom);
                measuredWidth  = Math.Max(measuredWidth, frame.Right);
            }

            var finalHeight = LayoutManager.ResolveConstraints(heightConstraint, FlexLayout.Height, measuredHeight, FlexLayout.MinimumHeight, FlexLayout.MaximumHeight);
            var finalWidth  = LayoutManager.ResolveConstraints(widthConstraint, FlexLayout.Width, measuredWidth, FlexLayout.MinimumWidth, FlexLayout.MaximumWidth);

            return(new Size(finalWidth, finalHeight));
        }