Question

So I am trying to subscribe the event MouseLeftButtonUp on an image element (lets name it "TheImage") in a WPF project. I want to be able to call the event handler when I click in the image element. How can I do that?

Was it helpful?

Solution

The Image class is a UIElement, so you can directly subscribe to MouseLeftButtonUp.

OTHER TIPS

Using MVVM approach, you'll need Galasoft MvvmLight (install via Nuget).

At head of your XAML:

xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WPF45"
         xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"

OBS.: if you're not using WPF45, replace "WPF45" for version that you're using, on

In your image:

<Image>
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="MouseLeftButtonUp">
            <cmd:EventToCommand Command="{Binding YourCommand, Mode=OneWay}" />
        </i:EventTrigger>
     </i:Interaction.Triggers>
</Image>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top