简体   繁体   English

检查画布子项是否存在

[英]Check if canvas child exists

So I'm adding rectangles from a list to my canvas and if I add the same one again I get this error: Specified Visual is already a child of another Visual or the root of a CompositionTarget. 因此,我将列表中的矩形添加到画布中,如果再次添加相同的矩形,则会出现此错误:指定的Visual已经是另一个Visual的子级或CompositionTarget的根。

this is my code to add: 这是我要添加的代码:

_canvas.Children.Add(rect);

Is there anyway I could check if child: rect already exists? 无论如何,我可以检查child:rect是否已经存在吗?

thanks. 谢谢。

你不能做_canvas.Children.Contains(rect)吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM