WPF MVVM:命令很简单。如何连接View和ViewModel与RoutedEvent [英] WPF MVVM : Commands are easy. How to Connect View and ViewModel with RoutedEvent

查看:258
本文介绍了WPF MVVM:命令很简单。如何连接View和ViewModel与RoutedEvent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个在资源字典中实现为DataTempate的视图。
我有一个相应的ViewModel。
绑定命令很简单。但是如果我的视图包含一个控件,如ListBox,而且我需要基于列表中更改的项目发布一个应用程序范围的事件(使用Prism的事件Aggreagtor)。



如果ListBox支持命令,我可以将其绑定到ViewModel中的命令并发布事件。但是Listbox不允许这样的选项。
如何桥接?



编辑:
很多很好的答案。



看看这个链接 http ://blogs.microsoft.co.il/blogs/tomershamam/archive/2009/04/14/wpf-commands-everywhere.aspx



谢谢



Ariel

解决方案

一个选项是扩展有问题的控件并添加对您需要的特定命令的支持。例如,我修改后的ListView 到支持 ItemActivated 事件和相关命令。


Suppose I have a view implemented as a DataTempate inside a resource Dictionary. And I have a corresponding ViewModel. Binding Commands are easy. But what if my View contains a control such as a ListBox, and I need to Publish an application wide event (Using Prism's Event Aggreagtor) based on the Item being Changed on the List.

if ListBox supports a command I could just bind it to a command in the ViewModel and publish the event. But Listbox doesn't allow such an option. How do I bridge this?

EDIT: Many great answers.

Take a look at this link http://blogs.microsoft.co.il/blogs/tomershamam/archive/2009/04/14/wpf-commands-everywhere.aspx

Thanks

Ariel

解决方案

One option is to extend the control in question and add support for the particular command you require. For example, I've modified ListView before to support the ItemActivated event and related command.

这篇关于WPF MVVM:命令很简单。如何连接View和ViewModel与RoutedEvent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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