---
title: "Get the source of image when user clicks it in c#"  
description: "Get the source of image when user clicks it in c#"  
author: "marcel ethan"  
published: 2014-08-14  
updated: 2014-08-14  
canonical: https://www.mindstick.com/forum/2041/get-the-source-of-image-when-user-clicks-it-in-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Get the source of image when user clicks it in c#

I have included four photos in xaml [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) 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](https://www.mindstick.com/interview/840/what-happens-if-the-both-source-and-destination-are-named-same) of the [image](https://www.mindstick.com/articles/23551/an-investigate-distinctive-seafood-restaurant-for-your-image-stamp-character) in "selected" [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server). 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?

## Replies

### Reply by Pravesh Singh

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;
```


---

Original Source: https://www.mindstick.com/forum/2041/get-the-source-of-image-when-user-clicks-it-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
