Skip to content

DragablzItemsControl size #3

@danielkaczmarek

Description

@danielkaczmarek

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions