Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DragablzItemsControl size #3

Open
danielkaczmarek opened this issue Oct 3, 2017 · 1 comment
Open

DragablzItemsControl size #3

danielkaczmarek opened this issue Oct 3, 2017 · 1 comment

Comments

@danielkaczmarek
Copy link

danielkaczmarek commented Oct 3, 2017

Hi,
Thank you for example, it looks cool and we’d like to implement it.
I’ve got one problem that I can’t get around until I modify one of your methods (which I don’t want to do until I must).
Basically, I want the DragablzItemsControl to start on as high as it need to be, and then as we add more records it should grow, until it reaches it maxheight then the scrollbar should appear. Instead the DragablzItemsControl height is the max from the beginning which can be seen if you change the background to a different color.
So, I noticed that the problems comes from here

   protected override Size MeasureOverride(Size constraint)
   {
        if (ItemsOrganiser == null) return base.MeasureOverride(constraint);

        if (LockedMeasure.HasValue)
        {
            ItemsPresenterWidth = LockedMeasure.Value.Width;
            ItemsPresenterHeight = LockedMeasure.Value.Height;
            return LockedMeasure.Value;
        }

        var dragablzItems = DragablzItems().ToList();
        var maxConstraint = new Size(double.PositiveInfinity, double.PositiveInfinity);

        ItemsOrganiser.Organise(this, maxConstraint, dragablzItems);
        var measure = ItemsOrganiser.Measure(this, new Size(ActualWidth, ActualHeight), dragablzItems);

        ItemsPresenterWidth = measure.Width;
        ItemsPresenterHeight = measure.Height;

        var width = double.IsInfinity(constraint.Width) ? measure.Width : constraint.Width;
        var height = double.IsInfinity(constraint.Height) ? measure.Height : constraint.Height;

        return new Size(width, height);
    }

The constraint width or height are never infinity, so these values always come back as constraint values. My fix is this

    protected override Size MeasureOverride(Size constraint)
    {
        if (ItemsOrganiser == null) return base.MeasureOverride(constraint);

        if (LockedMeasure.HasValue)
        {
            ItemsPresenterWidth = LockedMeasure.Value.Width;
            ItemsPresenterHeight = LockedMeasure.Value.Height;
            return LockedMeasure.Value;
        }

        var dragablzItems = DragablzItems().ToList();
        var maxConstraint = new Size(double.PositiveInfinity, double.PositiveInfinity);

        ItemsOrganiser.Organise(this, maxConstraint, dragablzItems);
        var measure = ItemsOrganiser.Measure(this, new Size(ActualWidth, ActualHeight), dragablzItems);

        ItemsPresenterWidth = measure.Width;
        ItemsPresenterHeight = measure.Height;

        var width = double.IsInfinity(constraint.Width) || (dragablzItems.Count > 0 && constraint.Width > measure.Width) ? measure.Width : constraint.Width;
        var height = double.IsInfinity(constraint.Height) || (dragablzItems.Count > 0 && constraint.Height > measure.Height) ? measure.Height : constraint.Height;

        return new Size(width, height);
    }

This way the itemscontrol always becomes as big as it needs to be for a given number of items, until it is bigger than the constraint then it does not grow any bigger and the scrollbar appears.
Hopefully it makes sense, is it possible for you to implement something like this, or is it a case that I must override this method in a derived class of my own?

Thank you

@ButchersBoy
Copy link
Contributor

Hi,

You can raise a PR for this, and I will test it in the main Dragablz demo...effectively I shouldnt see any change to how those tab controls work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants