首页 新闻 会员 周边

wp7/silverlight中,调用 Grid.Children.Add(XXX) 时,报错“参数不正确”/“The parameter is incorrect.

0
悬赏园豆:50 [已关闭问题] 关闭于 2012-03-12 12:20

我在编写一个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次都报错,

目前我还没有找到是什么原因导致的错误,

 

请高手们帮帮忙,如果需要,我可以提供源码给你们测试,

~冻结~的主页 ~冻结~ | 初学一级 | 园豆:39
提问于:2012-03-10 23:38
< >
分享
所有回答(2)
0

var pipeControl = new PipeControl();

pipeControl.Name = <唯一的Name>

~冻结~ | 园豆:39 (初学一级) | 2012-03-12 12:20
0

grid需要先定义总的行数、列数,然后再一一加入进去。

滴水成河 | 园豆:225 (菜鸟二级) | 2012-03-19 19:28
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册