MaterialDesignInXAML / MaterialDesignInXAML/MotionList
DragablzItemsControl size
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 248
- Forks
- 40
- PR merge metrics
- No merged PRs in 30d
Description
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
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with DragablzItemsControl.MeasureOverride and the ItemsOrganiser measurement calls shown in the issue. Reproduce the control with different item counts and a constrained height; done means it grows with its content until the constraint is reached, after which scrolling appears.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100