Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVVM View event Viewmodel command binding

I'm looking for a good (read: simple) example on how to implement event aggregators with Prism. I've never used Prism and I'm also quite new to MVVM itself.

I have a WPF canvas as a View and I want to handle the MouseUp event on the canvas in the Viewmodel. Now the powers that be at our organization wants me to use Prism, and apparently Prism recommends using event aggregators, which is why I need a sample to get me started.

like image 458
user823486 Avatar asked Jul 01 '26 00:07

user823486


1 Answers

all you need for this is the EventToCommand behavior from MVVMLight or from System.Windows.Interactivity (Blend SDK). i would recommend you to take the MVVMLight version because it has some usefull specials:)

<Canvas>
<i:Interaction.Triggers>
    <i:EventTrigger EventName="MouseUp" >
        <i:InvokeCommandAction Command="{Binding YourMouseUpViewModelCommand}" />
    </i:EventTrigger>
</i:Interaction.Triggers>
</Canvas>

EventAggregator from Prism i mostly used for decoupled Viewmodel to Viewmodel communication.

like image 184
blindmeis Avatar answered Jul 04 '26 01:07

blindmeis