I would like to delete some Rect object after IntersectsWith another one. For example:
if (rect1.IntersectsWith(rect2))
{
rect1.Remove()?!
}
How could I do that? Those rects are in myCanvas.Children, but I don't know how to get their index for myCanvas.Children.RemoveAt(index)
.
Use
if (rect1.IntersectsWith(rect2))
{
myCanvas.Children.Remove(rect1);
}
That way you don't need to find the index first.
In case you need the index use IndexOf
if (rect1.IntersectsWith(rect2))
{
var index = myCanvas.IndexOf(rect1);
if(index > -1)
{
myCanvas.Children.RemoveAt(index);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.