MVVM View事件Viewmodel命令绑定 [英] MVVM View event Viewmodel command binding

查看:184
本文介绍了MVVM View事件Viewmodel命令绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个很好的(阅读:简单)示例,该示例说明如何使用Prism实现事件聚合器.我从未使用过Prism,而且对MVVM本身也很陌生.

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.

我有一个WPF画布作为View,我想在Viewmodel中处理画布上的MouseUp事件.现在,我们组织的能力要求我使用Prism,并且显然Prism建议使用事件聚合器,这就是为什么我需要一个示例来使我入门.

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.

推荐答案

您所需要做的就是MVVMLight或System.Windows.Interactivity(Blend SDK)中的EventToCommand行为.我建议您使用MVVMLight版本,因为它具有一些有用的特色:)

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>

Prism的EventAggregator我主要用于将Viewmodel与Viewmodel通信分离.

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

这篇关于MVVM View事件Viewmodel命令绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆