From cedcb572cfa0c3f7903478d8b7ce051bc26739ab Mon Sep 17 00:00:00 2001 From: Mark Hewett Date: Tue, 9 Aug 2016 16:58:48 -0500 Subject: [PATCH] Added support for specifying SharedSizeGroup Can specify a shared size group for each column/row by adding the group name in parentheses to the Columns an/or Rows values, e.g. ... --- source/WpfAutoGrid/AutoGrid.cs | 36 ++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/source/WpfAutoGrid/AutoGrid.cs b/source/WpfAutoGrid/AutoGrid.cs index 8344247..4cab65e 100644 --- a/source/WpfAutoGrid/AutoGrid.cs +++ b/source/WpfAutoGrid/AutoGrid.cs @@ -168,7 +168,7 @@ public static void ColumnsChanged(DependencyObject d, DependencyPropertyChangedE var defs = Parse((string)e.NewValue); foreach (var def in defs) - grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = def }); + grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = def.Length, SharedSizeGroup = def.SharedSizeGroup }); } /// @@ -206,13 +206,14 @@ public static void FixedRowHeightChanged(DependencyObject d, DependencyPropertyC /// /// Parse an array of grid lengths from comma delim text /// - public static GridLength[] Parse(string text) + public static GridLengthInfo[] Parse(string text) { var tokens = text.Split(','); - var definitions = new GridLength[tokens.Length]; + var definitions = new GridLengthInfo[tokens.Length]; for (var i = 0; i < tokens.Length; i++) { - var str = tokens[i]; + var parts = tokens[i].Split('(', ')'); + var str = parts[0]; double value; // ratio @@ -221,19 +222,24 @@ public static GridLength[] Parse(string text) if (!double.TryParse(str.Replace("*", ""), out value)) value = 1.0; - definitions[i] = new GridLength(value, GridUnitType.Star); + definitions[i] = new GridLengthInfo() { Length = new GridLength(value, GridUnitType.Star) }; continue; } // pixels if (double.TryParse(str, out value)) { - definitions[i] = new GridLength(value); + definitions[i] = new GridLengthInfo() { Length = new GridLength(value) }; continue; } // auto - definitions[i] = GridLength.Auto; + definitions[i] = new GridLengthInfo() { Length = GridLength.Auto }; + + if (parts.Length > 1) + { + definitions[i].SharedSizeGroup = parts[1]; + } } return definitions; } @@ -273,7 +279,7 @@ public static void RowsChanged(DependencyObject d, DependencyPropertyChangedEven var defs = Parse((string)e.NewValue); foreach (var def in defs) - grid.RowDefinitions.Add(new RowDefinition() { Height = def }); + grid.RowDefinitions.Add(new RowDefinition() { Height = def.Length, SharedSizeGroup = def.SharedSizeGroup }); } /// @@ -325,8 +331,8 @@ private static void OnChildVerticalAlignmentChanged(DependencyObject d, Dependen /// Handled the redraw properties changed event /// private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) - { - + { + } /// @@ -480,8 +486,14 @@ protected override Size MeasureOverride(Size constraint) { this.PerformLayout(); return base.MeasureOverride(constraint); - } - + } + #endregion Overrides + } + + public class GridLengthInfo + { + public GridLength Length { get; set; } + public string SharedSizeGroup { get; set; } } } \ No newline at end of file