Example #1
0
        public virtual sw.Size MeasureOverride(sw.Size constraint, Func <sw.Size, sw.Size> measure)
        {
            // enforce eto-style sizing to wpf controls
            var size    = UserPreferredSize;
            var control = ContainerControl;

            // Constrain content to the preferred size of this control, if specified.
            var desired = measure(constraint.IfInfinity(size.InfinityIfNan()));
            // Desired size should not be smaller than default (minimum) size.
            // ensures buttons, text box, etc have a minimum size
            var defaultSize = DefaultSize.ZeroIfNan();

            desired = desired.Max(defaultSize);

            // Desired should also not be bigger than default size if we have no constraint.
            // Without it, controls like TextArea, GridView, etc will grow to their content.
            if (double.IsInfinity(constraint.Width) && defaultSize.Width > 0)
            {
                desired.Width = PreventUserResize ? defaultSize.Width : Math.Max(defaultSize.Width, desired.Width);
            }
            if (double.IsInfinity(constraint.Height) && defaultSize.Height > 0)
            {
                desired.Height = PreventUserResize ? defaultSize.Height : Math.Max(defaultSize.Height, desired.Height);
            }

            // use the user preferred size, and ensure it's not larger than available size
            size = size.IfNaN(desired);
            size = size.Min(constraint);

            // restrict to the min/max sizes
            size = size.Max(control.GetMinSize());
            size = size.Min(control.GetMaxSize());
            return(size);
        }
Example #2
0
 protected override sw.Size MeasureOverride(sw.Size availableSize)
 {
     if (IsLoaded)
     {
         availableSize = availableSize.IfInfinity(Handler.UserPreferredSize.IfNaN(Handler.DefaultSize));
     }
     return(Handler?.MeasureOverride(availableSize, base.MeasureOverride) ?? base.MeasureOverride(availableSize));
 }