如何在 WPF Datagrid 上拥有 MouseUp 和 MouseDoubleClick 事件
问题就在这里。我在 WPF 项目上使用 MVVM 并使用 MVVM light。我在用户控件中有一个网格,它返回搜索结果。我希望用户能够单击网格并使该行可供父视图使用(从菜单中)并拥有它,以便用户可以双击该行并在新的“窗口”中打开。就我个人而言,我让这些项目正常工作,但是我无法让两者都工作。我试图将 1 个命令绑定到 MouseUp,另一个命令绑定到 MouseDoubleClick,但 MouseDoubleClick 事件永远不会被触发。如何在 MVVM 设置中使用 mouseUp 和 MouseDoubleClick 事件?或任何其他建议,以便能够从数据网格中选择一行以供菜单项使用并能够双击。
Here is the problem. I am using MVVM on a WPF project and using MVVM light. I have a grid in a user control that returns results from a search. I want the users to be able to click on the grid and have the row available for the parent view to use (from a menu) and have it so users can double click on the row and open in a new "window". Individually I have these items work properly, however I can not get both to work. I am trying to tie 1 command to the MouseUp and another to MouseDoubleClick but the MouseDoubleClick event never gets fired. How can I be able to use the mouseUp and MouseDoubleClick events in a MVVM setup? or any other suggestions to be able to select a row from the datagrid to be available to menu items and to be able to doubleclick on.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 MVVMLight eventto 命令将为您提供选择更改和鼠标双击事件。
Using MVVMLight the eventtocommand will get you selectionchanged and mousedoubleclicked events.
我认为您将必须手动检测双击。
I think you're going to have to manually detect a double-click.
对于那些喜欢短途方式的人(也对 mvvm 友好!),
在您的 xaml 类中定义交互性:
在您的网格中:
希望有所帮助。
For those who love short ways (also mvvm friendly!),
define the interactivity in your xaml-class:
And in your Grid:
Hope that helps.