积极答复者
调用 Grid.Children.Add(XXX) 时,报错“参数不正确”/“The parameter is incorrect.”

问题
-
我在编写一个wp7小游戏的时,将若干个(42个)用户控件添加到Grid时报错:
“参数不正确”
“The parameter is incorrect.”
以下是代码:
grid_PipeContainer.Children.Clear(); for (int y = 0; y < this._plumberGame.VerticalPipesCount; y++) { for (int x = 0; x < this._plumberGame.HorizontalPipesCount; x++) { var pipe = this._plumberGame.PipesData[y, x]; var pipeControl = new PipeControl(); pipeControl.PipeType = pipe.Type; pipeControl.PipeDirection = pipe.Direction; pipeControl.IsThrough = pipe.IsThrough; pipeControl.Tag = pipe; Grid.SetRow(pipeControl, y); Grid.SetColumn(pipeControl, x); pipeControl.Click += new EventHandler(pipeControl_Click); grid_PipeContainer.Children.Add(pipeControl);//此处报错 } }
此错误并不是每次都报,如果用wp7模拟器的话,10次里有7次都报错,部署到真机上,10次有3次都报错,
目前我还没有找到是什么原因导致的错误,
请高手们帮帮忙,如果需要,我可以提供源码给你们测试,
- 已编辑 jesse hao 2012年3月10日 11:03 错别字
答案
-
你好,我这边debug了一下。发现是PipeControl Name属性的问题。如果去掉PipeControl.xaml 里面x:Name的定义,异常就没有抛出了。
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
Delete this -> x:Name="userControl" x:Class="PlumberWP7.PipeControl"
mc:Ignorable="d"
d:DesignHeight="80" d:DesignWidth="80" MouseLeftButtonUp="UserControl_MouseLeftButtonUp">- 已标记为答案 jesse hao 2012年3月13日 10:39
全部回复
-
十分感谢您的回答,我也做过类似的测试,错误确实没有重现过,实在令人头疼,
我将源码上传到skydrive上了,地址是:
错误发生在项目根目录下的“Playing.xaml.cs”文件中,我加了个“todo”任务以标注:// todo:报错报错报错报错报错报错报错报错报错报错报错报错
将它部署到模拟器上,运行,主页面上点击“开始游戏”,然后随便选择一个关卡,进入游戏页面,次错误就会发生,(如果未报错,请“返回”到选择关卡页面再次点进去,反复几次),
初学者,代码过于混乱,请多包涵,
-
你好,我这边debug了一下。发现是PipeControl Name属性的问题。如果去掉PipeControl.xaml 里面x:Name的定义,异常就没有抛出了。
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
Delete this -> x:Name="userControl" x:Class="PlumberWP7.PipeControl"
mc:Ignorable="d"
d:DesignHeight="80" d:DesignWidth="80" MouseLeftButtonUp="UserControl_MouseLeftButtonUp">- 已标记为答案 jesse hao 2012年3月13日 10:39
-
过奖。
这个问题我也无法解释。但是我已经递交到Connect.Microsoft网站上,会有相应的产品组的人来分析这个问题的。你可以跟踪这个链接随时查看处理的进度。
-
你好,如果方便的话,能把这个问题也提交给Connect.Microsoft网站吗?本人外语水平有限,地址是: