我在编写一个wp7小游戏的时,将若干个(42个)用户控件添加到Grid时报错:
“参数不正确”
“The parameter is incorrect.”
以下是代码:
1 grid_PipeContainer.Children.Clear();
2 for (int y = 0; y < this._plumberGame.VerticalPipesCount; y++)
3 {
4 for (int x = 0; x < this._plumberGame.HorizontalPipesCount; x++)
5 {
6 var pipe = this._plumberGame.PipesData[y, x];
7
8 var pipeControl = new PipeControl();
9 pipeControl.PipeType = pipe.Type;
10 pipeControl.PipeDirection = pipe.Direction;
11 pipeControl.IsThrough = pipe.IsThrough;
12 pipeControl.Tag = pipe;
13 Grid.SetRow(pipeControl, y);
14 Grid.SetColumn(pipeControl, x);
15 pipeControl.Click += new EventHandler(pipeControl_Click);
16
17 grid_PipeContainer.Children.Add(pipeControl);//此处报错
18 }
19 }
此错误并不是每次都报,如果用wp7模拟器的话,10次里有7次都报错,部署到真机上,10次有3次都报错,
目前我还没有找到是什么原因导致的错误,
请高手们帮帮忙,如果需要,我可以提供源码给你们测试,
var pipeControl = new PipeControl();
pipeControl.Name = <唯一的Name>
grid需要先定义总的行数、列数,然后再一一加入进去。