J'ai écrit cette méthode environ 3 fois maintenant et je suis certain que je ne vais pas faire écrire pendant un certain temps:Filler Grille générique Extension Méthode
public void PopulateField() {
this.grdNameField.ColumnDefinitions.Clear();
this.grdNameField.RowDefinitions.Clear();
this.grdNameField.Children.Cast<Viewbox>().ToList().ForEach(VB => VB.Child = null);
this.grdNameField.Children.Clear();
for (int x = 0; x < Settings.Default.PlayerCount; x++) {
Viewbox VB = new Viewbox() { Child = this.PlayerNamers[x], Stretch = Stretch.Uniform };
this.grdNameField.Children.Add(VB);
Grid.SetColumn(VB, x % Math.Max(3, (int)(Math.Ceiling(Settings.Default.PlayerCount/5.0D))));
Grid.SetRow(VB, x/Math.Max(3, (int)(Math.Ceiling(Settings.Default.PlayerCount/5.0D))));
}
int
ColumnCount = this.grdNameField.Children.Cast<Viewbox>().Max(VB => Grid.GetColumn(VB)) + 1,
RowCount = this.grdNameField.Children.Cast<Viewbox>().Max(VB => Grid.GetRow(VB)) + 1;
for (int x = 0; x < ColumnCount; x++)
this.grdNameField.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) });
for (int x = 0; x < RowCount; x++)
this.grdNameField.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) });
}
J'ai enfin remarqué que la différence entre les trois fonctions est seulement ce que la grille est remplie: Une liste générique d'objets Liste (et à l'occasion, à quoi la propriété Viewbox Stretch est définie).
Je veux écrire une méthode générique pour remplacer ces trois (et toutes les futures) méthodes et j'ai une idée de comment le faire ...