/// <summary> /// Turns a string of lengths, such as "3*,Auto,2000" into a set of gridlength. /// </summary> /// <param name="lengths">The string of lengths, separated by commas.</param> /// <returns>A list of GridLengths.</returns> private static List <GridLength> StringLengthsToGridLengths(string lengths) { // Create the list of GridLengths. List <GridLength> gridLengths = new List <GridLength>(); // If the string is null or empty, this is all we can do. if (string.IsNullOrEmpty(lengths)) { return(gridLengths); } // Split the string by comma. string[] theLengths = lengths.Split(','); // Use a consistency grid length converter. Consistency.GridLengthConverter gridLengthConverter = new Consistency.GridLengthConverter(); // Convert the lengths. foreach (var length in theLengths) { gridLengths.Add(gridLengthConverter.ConvertFromString(length)); } // Return the grid lengths. return(gridLengths); }
private static void OnGridPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args) { // Get the grid. VariableGrid me = dependencyObject as VariableGrid; // Clear the rows and columns. me.RowDefinitions.Clear(); me.ColumnDefinitions.Clear(); // Rows and columns must be positive. if (me.Rows < 0 || me.Columns < 0) { return; } // Create a grid length converter. Consistency.GridLengthConverter gridLengthConverter = new Consistency.GridLengthConverter(); // Add each row. for (int i = 0; i < me.Rows; i++) { me.RowDefinitions.Add(new RowDefinition() { Height = gridLengthConverter.ConvertFromString(me.RowHeight) }); } // Add each column. for (int i = 0; i < me.Columns; i++) { me.ColumnDefinitions.Add(new ColumnDefinition() { Width = gridLengthConverter.ConvertFromString(me.ColumnWidth) }); } }