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?

Était-ce utile?

La solution

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

Autres conseils

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>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top