1
一個UniformGrid在C#我是比較新的C#和我試圖創建一個窗口與相同尺寸的正方形的動態量的網格。正方形然後通過一個過程改變它們的顏色。繪畫使用WPF
我正在努力產生正方形的網格。每當我運行這個應用程序時,它似乎都會在資源上瘋狂,我不知道爲什麼。
我使用的代碼如下:
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);
}
}
}
這甚至我想借此如果我想正方形的修改網格的方法呢?
感謝您的幫助,
傑森
爲什麼不使用WPF均勻網格? –
100 * 100 = 10000 GDI一次處理,難怪這是忙碌=) –
@ SebastianEdelmeier GDI!?!?!這是WPF不蹩腳的winforms。 –