Home > DeveloperSection > Forums > Get the source of image when user clicks it in c#
marcel ethan
marcel ethan

Total Post:105

Points:735
Posted on    August-14-2014 5:14 AM

 C# C# 
Ratings:


 1 Reply(s)
 846  View(s)
Rate this:

I have included four photos in xaml code as follows

                <Image Grid.Column="0"

                       Source="Assets/1.png"

                       Name="m1"

                       MouseLeftButtonDown="selected"/>

                <Image Grid.Column="1"

                       Source="Assets/2.png"

                       Name="m2"

                       MouseLeftButtonDown="selected"/>

                <Image Grid.Column="2"

                       Source="Assets/3.png"

                       Name="m3"

                       MouseLeftButtonDown="selected"/>

                <Image Grid.Column="3"

                       Source="Assets/4.png"

                       Name="m4"

                       MouseLeftButtonDown="selected"/>

I want to get the source of the image in "selected" function. my selected function is as follows

private void selected(object sender, MouseButtonEventArgs e)

    {

        //do somethings....

    }

How can i assign the source of the selected image(sender) to a new Image object?. something similar to follows

Image newimage = new Image();

newimage.Source = //something..

Is there a way to dynamically get the source?



Pravesh Singh

Total Post:411

Points:2881
Posted on    August-14-2014 6:55 AM

Hi Marcel, 

Use OriginalSource property of event and cast it to Image:

var clickedImage = (Image)e.OriginalSource;

Image newimage = new Image();

newimage.Source = clickedImage.Source;


Don't want to miss updates? Please click the below button!

Follow MindStick