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。 –