私はC#に比較的慣れていないので、同じサイズの正方形の動的な量のグリッドを持つウィンドウを作成しようとしています. 次に、プロセスによって正方形の色が変更されます。
現在、正方形のグリッドを生成するのに苦労しています。アプリケーションを実行するたびに、リソースに夢中になっているように見えますが、その理由はわかりません。
私が使用しているコードは次のとおりです。
private void Window_Loaded(object sender, RoutedEventArgs e) {
//create a blue brush
SolidColorBrush vBrush = new SolidColorBrush(Colors.Blue);
//set the columns and rows to 100
cellularGrid.Columns = mCellAutomaton.GAME_COLUMNS;
cellularGrid.Rows = mCellAutomaton.GAME_ROWS;
//change the background of the cellular grid to yellow
cellularGrid.Background = Brushes.Yellow;
//create 100*100 blue rectangles to fill the cellular grid
for (int i = 0; i < mCellAutomaton.GAME_COLUMNS; i++) {
for (int j = 0; j < mCellAutomaton.GAME_ROWS; j++) {
Rectangle vRectangle = new Rectangle();
vRectangle.Width = 10;
vRectangle.Height = 10;
vRectangle.Fill = vBrush;
cellularGrid.Children.Add(vRectangle);
}
}
}
変更可能な正方形のグリッドが必要な場合、これは私が取りたいアプローチですか?
助けてくれてありがとう、
ジェイソン