private static void CharWidthPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { CharacterDesigner designer = (CharacterDesigner)d; StackPanel rows = designer.rows; uint newValue = (uint)e.NewValue; if (newValue > (uint)e.OldValue) { foreach (StackPanel row in rows.Children) { do { row.Children.Add(designer.GetNewCell()); }while (row.Children.Count != newValue); } } else { int newValueInt = (int)newValue; foreach (StackPanel row in rows.Children) { for (int column = row.Children.Count - 1; column > newValueInt - 1; column--) { TextBlock cell = (TextBlock)row.Children[column]; row.Children.RemoveAt(column); designer.StoreUnusedCell(cell); } } } }
private static void CharHeightPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { CharacterDesigner designer = (CharacterDesigner)d; StackPanel rows = designer.rows; uint newValue = (uint)e.NewValue; if (rows.Children.Count < newValue) { do { StackPanel row = designer.GetNewRow(); for (int i = 0; i < designer.CharWidth; i++) { row.Children.Add(designer.GetNewCell()); } rows.Children.Add(row); }while (rows.Children.Count != newValue); } else { int newValueInt = (int)newValue; for (int row = rows.Children.Count - 1; row > newValueInt - 1; row--) { StackPanel rowElement = (StackPanel)rows.Children[row]; for (int column = rowElement.Children.Count - 1; column >= 0; column--) { TextBlock cell = (TextBlock)rowElement.Children[column]; rowElement.Children.RemoveAt(column); designer.StoreUnusedCell(cell); } rows.Children.RemoveAt(row); designer.StoreUnusedRow(rowElement); } } }