将 ViewModel 命令绑定到 WPF DataGrid
是否有一种友好且快速的方法将命令绑定到 WPF DataGrid
双击事件?
我使用过搜索框,但我找到的所有结果都有很多行代码,而且不太实用。
Is there a friendly and fast way of bind a command to a WPF DataGrid
double click event?
I've used the search box, but all the results I've found had a lot of lines of code and weren't that practical to use.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是实现模型-视图-视图模型 (MVVM) 的普遍愿望,但开箱即用并不容易。我还没有使用过它,但据我所知,使用 MVVM Light Toolkit 可以让你做这样的事情。
或者,如果您不希望这样,还有其他方案: WPF:如何使用 MVVM 将命令绑定到 ListBoxItem?
但是,一般来说,没有快速简便的方法来执行此操作。
This is a common desire for implementing Model-View-ViewModel (MVVM) in general, and not easily available out of the box. I haven't used it, but from what I've seen, using the MVVM Light Toolkit will allow you to do things like this.
Or, if you don't want that, there are other schemes as well: WPF: How to bind a command to the ListBoxItem using MVVM?
But, generally speaking, there's no quick and easy ways to do this.
您不能“绑定”事件,事件属于代码隐藏。有一些解决方法,您可以创建一些自定义行为等,但恕我直言,如果您跳过这些障碍,那么您没有正确执行 MVVM,您正在尝试跨越事件驱动和 MVVM 之间的界限。
作为一个简单的解决方法,您可以简单地添加一个事件处理程序来调用视图模型上的方法。
You can't "Bind" events, events belong in the code-behind. There are some work-arounds, you could create some custom behaviors and such, but IMHO if you're jumping through those hoops, you're not doing MVVM properly, you're trying to straddle the fence between event driven and MVVM.
As a simple work around, you can simply add an event handler that calls a method on your view model.