Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for specifying SharedSizeGroup #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
36 changes: 24 additions & 12 deletions source/WpfAutoGrid/AutoGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}

/// <summary>
Expand Down Expand Up @@ -206,13 +206,14 @@ public static void FixedRowHeightChanged(DependencyObject d, DependencyPropertyC
/// <summary>
/// Parse an array of grid lengths from comma delim text
/// </summary>
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
Expand All @@ -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;
}
Expand Down Expand Up @@ -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 });
}

/// <summary>
Expand Down Expand Up @@ -325,8 +331,8 @@ private static void OnChildVerticalAlignmentChanged(DependencyObject d, Dependen
/// Handled the redraw properties changed event
/// </summary>
private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
{
}

/// <summary>
Expand Down Expand Up @@ -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; }
}
}