---
title: "How to change an event's sender in WPF/XAML"  
description: "How to change an event's sender in WPF/XAML"  
author: "Anonymous User"  
published: 2013-12-27  
updated: 2013-12-27  
canonical: https://www.mindstick.com/forum/1845/how-to-change-an-event-s-sender-in-wpf-xaml  
category: "wpf"  
tags: ["wpf"]  
reading_time: 1 minute  

---

# How to change an event's sender in WPF/XAML

I want to set the sender of an event to something other than the actual initiator of the event. Consider this [simple](https://yourviews.mindstick.com/story/1469/5-simple-ways-to-stay-fit-amp-healthy) DataTemplate for my CImage class:

```
<DataTemplate DataType="{x:Type er:CImage}">    <Grid VerticalAlignment="Center" HorizontalAlignment="Center"
Margin="5">        <StackPanel Orientation="Vertical" MaxWidth="{Binding Image.Width}">            <Image Source="{Binding Image}" MouseUp="MouseUpHandler" />            <Label Content="{Binding ImageFile.Name}" />           
<Label>               
<TextBlock  TextWrapping="WrapWithOverflow" Text="{Binding TagsJoined}" />           
</Label>       
</StackPanel>    </Grid></DataTemplate>
```

When the [user clicks](https://answers.mindstick.com/qa/34556/if-a-user-clicks-all-the-google-ads-on-my-site-is-it-foul) on this:

<[Image Source](https://www.mindstick.com/forum/34428/how-to-remove-image-source-from-html-content)="{[Binding](https://www.mindstick.com/blog/146/dynamic-binding-in-c-sharp) ImageSource}" MouseUp="MouseUpHandler" />

The "MouseUpHandler" [event handler](https://www.mindstick.com/forum/1371/c-sharp-dot-net-event-handler-delegate-question) needs [access](https://www.mindstick.com/articles/12994/how-foreigners-can-access-blocked-websites-in-china) to the "Image" object of which "ImageSource" is a [property](https://www.mindstick.com/blog/205/property-notification-in-c-sharp), not the "Image" object to which "ImageSource" has been bound.

Is there any way to communicate this information in the event itself or do I have no [choice](https://yourviews.mindstick.com/view/80821/it-s-not-easy-to-make-a-right-choice) but to have the handler look up the Image through other means?

## Replies

### Reply by Anonymous User

Hi Jay,

Sender will always be Image object, that you can't change.

However, in [handler](https://www.mindstick.com/forum/33532/handler-pagehandlerfactory-integrated-has-a-bad-module-managedpipelinehandler-in-its-module-list) you can access DataContext of Image which will be object of CImage since DataType of DataTemplate is CImage:

```
private void MouseUpHandler(object sender, MouseButtonEventArgs e){    CImage instance = (CImage)((Image)sender).DataContext;}
```


---

Original Source: https://www.mindstick.com/forum/1845/how-to-change-an-event-s-sender-in-wpf-xaml

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
