我有一个有 400 个孩子的 Canvas。每个孩子都是一个矩形,并用图像填充。如果我想找到某个图像,我会怎么做?
//My code to fill a rectangle
Image img = new Image();
img.Source = new BitmapImage(new Uri(@"hero.png", UriKind.Relative));
img.Margin = rec.Margin;
ImageBrush imgbrush = new ImageBrush();
imgbrush.ImageSource = img.Source;
rec.Fill = imgbrush;
//My attempt at finding that certain rectangle
foreach (Rectangle rec in canvas1.Children)
{
if (rec.Fill = ImageBrush.ImageSourceProperty) // I tried to compare the rectangle with the image's source
{
}
}