Silverlight用FindName搜索找不到控件名是怎么回事?(急)

heren5201314 heren5201314 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我用传参的方式传值:
Rectangle rt = FindName(myName + i) as Rectangle ,
想把找到的控件隐藏
但是rt有时候会出现异常(未将对象引用到对象的实例),找不到控件,值为null,但是有时候又是好的,没什么问题!
这是什么情况? 不明白。我rt是动态命名:如下。
if (listTak.ElementAt(i).NumSleep == 1)
{
re.Name = "rtSleeping" + i;
re.Fill = new SolidColorBrush(Colors.Blue);
myTitle = "熟睡";
}
else if (listTak.ElementAt(i).NumSleep == 2)
{
re.Name = "rtShallow" + i;
re.Fill = new SolidColorBrush(Colors.Orange);
myTitle = "浅睡";
}
else if (listTak.ElementAt(i).NumSleep == 3)
{
re.Name = "rtDreaming" + i;
re.Fill = new SolidColorBrush(Colors.Red);
myTitle = "做梦";
}
else if (listTak.ElementAt(i).NumSleep == 4)
{
re.Name = "rtSop" + i;
re.Fill = new SolidColorBrush(Colors.Green);
myTitle = "疑似呼吸中止症";
}
实在想不懂,请各位帮帮忙!
...全文

相关推荐

评论 11
收藏 已收藏
分享
返回顶部
heren5201314
WPF/Silverlight 8,757 成员 12,031 内容