Esempio n. 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);
        }
Esempio n. 2
0
        protected virtual void SetSize()
        {
            // this is needed so that the control doesn't actually grow when its content is too large.
            // For some reason, MeasureOverride is not sufficient alone to tell WPF what size the control should be.
            // for example, when a TextBox has a large amount of text, we do not grow the text box to fit that content in Eto's sizing model.
            // ideally, this should be removed, but may require overriding ArrangeOverride on all controls as well.
            // see the ControlTests.ControlsShouldHaveSaneDefaultWidths unit test for repro of the issue.
            var defaultSize = DefaultSize.ZeroIfNan();

            if (XScale && Control.IsLoaded)
            {
                ContainerControl.Width    = double.NaN;
                ContainerControl.MinWidth = 0;
            }
            else
            {
                var containerWidth = PreventUserResize && double.IsNaN(UserPreferredSize.Width)
                                        ? defaultSize.Width <= 0
                                                ? double.NaN
                                                : defaultSize.Width
                                        : UserPreferredSize.Width;
                ContainerControl.Width    = Math.Max(containerWidth, parentMinimumSize.Width);
                ContainerControl.MinWidth = Math.Max(0, double.IsNaN(UserPreferredSize.Width) ? defaultSize.Width : UserPreferredSize.Width);
            }

            if (YScale && Control.IsLoaded)
            {
                ContainerControl.Height    = double.NaN;
                ContainerControl.MinHeight = 0;
            }
            else
            {
                var containerHeight = PreventUserResize && double.IsNaN(UserPreferredSize.Height)
                                        ? defaultSize.Height <= 0
                                                ? double.NaN
                                                : defaultSize.Height
                                        : UserPreferredSize.Height;
                ContainerControl.Height    = Math.Max(containerHeight, parentMinimumSize.Height);
                ContainerControl.MinHeight = Math.Max(0, double.IsNaN(UserPreferredSize.Height) ? defaultSize.Height : UserPreferredSize.Height);
            }
        }