How to link image on canvas with an object

1

I have the following class:

class Sapo
{
    private Image imgSapo;

    public int IdSapo { get; }

    public Sapo(int id)
    {
        imgSapo = new Image();
        IdSapo = id;
    }

    public Image show
    {
        get 
        {
            imgSapo.Source = new BitmapImage(new Uri("pack://application:,,,/Imagens/sapo.png", UriKind.Absolute));
            imgSapo.Width = 56;
            imgSapo.Height = 56;

            return imgSapo;
        }
    }
}

And I have a method where I create a thread passing an instance of each Toad class object:

public void CriarSapos()
{
    Thread th;

    int sapos = int.Parse(txt_sapos.Text);

    Sapo[] arraySapos = new Sapo[sapos];

    for (int i = 0; i < sapos; i++)
    {
        th = new Thread(new ParameterizedThreadStart(ThreadImageSapo));
        th.SetApartmentState(ApartmentState.STA);
        th.IsBackground = true;
        arraySapos[i] = new Sapo(th.ManagedThreadId);
        th.Start(arraySapos[i]);
    }
}

The method responsible for inserting the images on the canvas:

public void ThreadImageSapo(object obj)
{
    Dispatcher.Invoke(() =>
    {
        Sapo _sapo = (Sapo)obj;

        double max_x = _canvas.ActualWidth - _sapo.show.Width;
        double max_y = _canvas.ActualHeight - _sapo.show.Height;

        Canvas.SetLeft(_sapo.show, rnd.NextDouble() * max_x);
        Canvas.SetTop(_sapo.show, rnd.NextDouble() * max_y);

        _canvas.Children.Add(_sapo.show);

    });
}

How can I take pictures of the canvas and its object?

    
asked by anonymous 28.11.2016 / 17:33

0 answers