WPF 事件捕获。控制触发 mouseup 但不触发 mousedown
我读过几篇有关相关问题的文章,这篇文章似乎不一致。
我有一个数据网格控件,我需要在单击鼠标时捕获鼠标位置。我有代码可以在 mouseup 和 mousedown 事件处理程序中执行此操作。 mousedown 是我想要的,但该事件从未被触发。我将代码放在那里并设置了一个断点,但它永远不会到达该点。然而,鼠标按下确实会按应有的方式触发,但这不是我需要的事件,并且我得到了不可预测的结果。
有没有相关文章来解释发生了什么?我认为这是某种路由事件问题。但为什么 mouseup 可以工作,而 mousedown 却不能呢?如何修复我的代码,以便所有事件在应有的时候触发?
I've read a few articles on related issues and this one seems to be inconsistent.
I have a datagrid control in which I need to capture mouse location when the mouse is clicked. I have code to do this in the mouseup and mousedown event handlers. mousedown is what I want, but that event is never fired. I put the code there and set a breakpoint and it never reaches that point. the mouseup however does fire just as it should, but its not the event I need and I'm getting unpredictable results.
are there any articles on this to explain what's happening? I assume its some kind of a routed event issue. but why would mouseup work but mousedown not? How can I fix my code so that all the events fire when they should?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
发生此问题是因为数据网格中的单元格正在捕获 MouseDown 事件。您可以尝试通过以下方式在代码中订阅该事件:
或者,如果这不是您想要做的,我相信还有一个 PreviewMouseDown 事件已分配给您可以使用的 DataGrid。
我希望这有帮助。
The issue is happening because the cells in the datagrid are capturing the MouseDown events. You can try to subscribe to that event in code via:
Or if that's not what you're wanting to do there's also, I believe, a PreviewMouseDown event that's already assigned to a DataGrid that you can use.
I hope this helps.