0

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
            {

            }                
        }
4

2 に答える 2

1

特定の名前ごとに名前を使用してから、FindNameメソッドImageを使用できます

object wantedNode = stackPanel.FindName("dog");
于 2013-03-01T16:29:48.810 に答える
0

後で反復できる配列(キー/ペア)にオブジェクトを格納してみませんか?

于 2013-03-02T01:58:36.710 に答える