Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions components/Ribbon/src/RibbonPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,25 @@ protected override Size MeasureOverride(Size availableSize)
// We try to limit the layout changes if the parent scrollviewer is sending values with small changes.
availableSize.Width = Math.Floor(availableSize.Width);

var childrenByPriority = Children.OrderBy(c => c is RibbonCollapsibleGroup collapsibleGroup ? collapsibleGroup.Priority : 0);
var childrenByPriority = Children
.OrderBy(c => c is RibbonCollapsibleGroup collapsibleGroup ? collapsibleGroup.Priority : 0)
.ToList();

var desiredSize = new Size();
foreach (var child in childrenByPriority)
{
var collapsibleGroup = child as RibbonCollapsibleGroup;
var requestedWidths = collapsibleGroup?.RequestedWidths;
if (requestedWidths is null || collapsibleGroup?.State == Visibility.Collapsed)
if (requestedWidths is null || collapsibleGroup!.State == Visibility.Collapsed)
{
child.Measure(GroupAvailableSize);
}
else
{
// Get the closest match to remainingWidth or use infinite size if we do not have any match.
var remainingWidth = availableSize.Width - desiredSize.Width;
//var requestedWidth = requestedWidths.LastOrDefault(w => w <= remainingWidth, defaultValue: double.PositiveInfinity);
var matchingWidths = requestedWidths.Where(w => w <= remainingWidth);
var requestedWidth = matchingWidths.Any() ? matchingWidths.Last() : double.PositiveInfinity;
var matchingWidth = requestedWidths.LastOrDefault(w => w <= remainingWidth);
var requestedWidth = matchingWidth > 0 ? matchingWidth : double.PositiveInfinity;
var fixedSize = new Size(requestedWidth, availableSize.Height);
child.Measure(fixedSize);
}
Expand All @@ -46,7 +48,7 @@ protected override Size MeasureOverride(Size availableSize)
{
// We need to collapse some groups.
// If there is no priority order we assume that the last items are the one which should collapse first.
var groups = Children.OfType<RibbonCollapsibleGroup>().Reverse().Where(g => g.State == Visibility.Visible).OrderByDescending(g => g.Priority);
var groups = childrenByPriority.OfType<RibbonCollapsibleGroup>().Reverse().Where(g => g.State == Visibility.Visible);
foreach (var group in groups)
{
group.State = Visibility.Collapsed;
Expand Down Expand Up @@ -76,7 +78,7 @@ protected override Size MeasureOverride(Size availableSize)
else if (desiredSize.Width < availableSize.Width)
{
// We have more space than needed, we check if we can expand some groups
var groups = Children.OfType<RibbonCollapsibleGroup>().Where(g => g.State == Visibility.Collapsed).OrderBy(g => g.Priority);
var groups = childrenByPriority.OfType<RibbonCollapsibleGroup>().Where(g => g.State == Visibility.Collapsed);
foreach (var group in groups)
{
var previousSize = group.DesiredSize;
Expand All @@ -91,9 +93,8 @@ protected override Size MeasureOverride(Size availableSize)
{
// Get the closest match to remainingWidth or use infinite size if we do not have any match.
var remainingWidth = availableSize.Width + previousSize.Width - desiredSize.Width;
//var requestedWidth = requestedWidths.LastOrDefault(w => w <= remainingWidth, defaultValue: double.PositiveInfinity);
var matchingWidths = requestedWidths.Where(w => w <= remainingWidth);
var requestedWidth = matchingWidths.Any() ? matchingWidths.Last() : double.PositiveInfinity;
var matchingWidth = requestedWidths.LastOrDefault(w => w <= remainingWidth);
var requestedWidth = matchingWidth > 0 ? matchingWidth : double.PositiveInfinity;
var fixedSize = new Size(requestedWidth, availableSize.Height);
group.Measure(fixedSize);
}
Expand Down
Loading