传递事件参数和发送者的RelayCommand

编程入门 行业动态 更新时间:2024-10-11 21:20:57
本文介绍了传递事件参数和发送者的RelayCommand的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何使用RelayCommand当你发送的事件?

How do you get event sender when using RelayCommand?

推荐答案

这是其中的一个痛苦的,任何─%¤#的答案,我并没有真正回答你的问题,而是你说教什么,你应该做不同。所以,我们对此深感抱歉。这里有云:

This is one of those pain-in-the-%¤# answers where I don't actually answer your question, but instead lecture you about what you should be doing differently. So, sorry about that. Here goes:

如果你发现自己在你需要得到在您的视图模型发送对象的位置,那么你或许应该做不同的事情。通过引用,说,一个按钮或在您的视图模型的列表框,你所做的视图模型了解用户界面的概念,它不应该知道的事情。我的建议是不是挂钩到在code-隐藏页面的情况下,找出你需要知道发送者或什么,而不是,然后以编程方式执行视图模型命令。这也打破了MVVM规则,但恕我直言,这是一个非常细微的黑客比引用发件人在你的视图模型。

If you find yourself in a position where you need to get at the sender object in your viewmodel, then you should probably do something different. By referencing, say, a Button or a ListBox in your viewmodel you have made that viewmodel aware of UI concepts that it should not know anything about. My suggestion is to instead hook up to the event in the code-behind page, find out what you need to know about the sender or what-not, and then execute the viewmodel command programmatically. That is also breaking the MVVM "rules", but IMHO it is a much slighter hack than referencing the sender in your viewmodel.

更多推荐

传递事件参数和发送者的RelayCommand

本文发布于:2023-11-25 20:14:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1631192.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:参数   事件   RelayCommand

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!