From b70fab00c7bf8f3c2641a065e7dd137a642e881f Mon Sep 17 00:00:00 2001 From: Kris McGinnes Date: Thu, 1 Dec 2016 08:31:08 -0600 Subject: [PATCH] Add Fill type of Ignored --- src/AutoGrid/StackPanel.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/AutoGrid/StackPanel.cs b/src/AutoGrid/StackPanel.cs index 66e997e..e9f875c 100644 --- a/src/AutoGrid/StackPanel.cs +++ b/src/AutoGrid/StackPanel.cs @@ -17,7 +17,7 @@ protected override Size MeasureOverride(Size constraint) double accumulatedHeight = 0; var isHorizontal = Orientation == Orientation.Horizontal; - var totalMarginToAdd = CalculateTotalMarginToAdd(children, isHorizontal, MarginBetweenChildren); + var totalMarginToAdd = CalculateTotalMarginToAdd(children, MarginBetweenChildren); for (int i = 0; i < children.Count; i++) { @@ -123,16 +123,16 @@ protected override Size ArrangeOverride(Size arrangeSize) var isHorizontal = Orientation == Orientation.Horizontal; var marginBetweenChildren = MarginBetweenChildren; - var totalMarginToAdd = CalculateTotalMarginToAdd(children, isHorizontal, marginBetweenChildren); + var totalMarginToAdd = CalculateTotalMarginToAdd(children, marginBetweenChildren); double allAutoSizedSum = 0.0; int countOfFillTypes = 0; foreach (var child in children.OfType()) { var fillType = GetFill(child); - if (fillType == StackPanelFill.Fill) + if (fillType != StackPanelFill.Auto) { - if (child.Visibility != Visibility.Collapsed) + if (child.Visibility != Visibility.Collapsed && fillType != StackPanelFill.Ignored) countOfFillTypes += 1; } else @@ -152,10 +152,10 @@ protected override Size ArrangeOverride(Size arrangeSize) UIElement child = children[i]; if (child == null) { continue; } Size childDesiredSize = child.DesiredSize; - var isCollapsed = child.Visibility == Visibility.Collapsed; + var fillType = GetFill(child); + var isCollapsed = child.Visibility == Visibility.Collapsed || fillType == StackPanelFill.Ignored; var isLastChild = i == totalChildrenCount - 1; var marginToAdd = isLastChild || isCollapsed ? 0 : marginBetweenChildren; - var fillType = GetFill(child); Rect rcChild = new Rect( accumulatedLeft, @@ -182,11 +182,11 @@ protected override Size ArrangeOverride(Size arrangeSize) return arrangeSize; } - static double CalculateTotalMarginToAdd(UIElementCollection children, bool isHorizontal, double marginBetweenChildren) + static double CalculateTotalMarginToAdd(UIElementCollection children, double marginBetweenChildren) { var visibleChildrenCount = children .OfType() - .Count(x => x.Visibility != Visibility.Collapsed); + .Count(x => x.Visibility != Visibility.Collapsed && GetFill(x) != StackPanelFill.Ignored); var marginMultiplier = Math.Max(visibleChildrenCount - 1, 0); var totalMarginToAdd = marginBetweenChildren * marginMultiplier; return totalMarginToAdd; @@ -240,6 +240,6 @@ public static StackPanelFill GetFill(DependencyObject element) public enum StackPanelFill { - Auto, Fill + Auto, Fill, Ignored } }