문제

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?

도움이 되었습니까?

해결책

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

다른 팁

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>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top