我有一个有400个孩子的画布。每个孩子都是一个矩形,并充满了一个图像。如果我想找到某个图像,我该如何处理呢?
//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
{
}
}
答案 0 :(得分:1)
答案 1 :(得分:0)
为什么不将对象存储在稍后可以迭代的数组(键/对)中?