鼠标左键弹起事件和openfiledialog
我的网格中只有几个图像,然后当我单击按钮时,会出现一个“打开文件对话框”。(当然,在图像上方)
Microsoft.Win32.OpenFileDialog dlgOpenFiles = new Microsoft.Win32.OpenFileDialog(); dlgOpenFile.DoModal();
这些图像附加了 LeftButtonUp 事件。问题是,如果我通过双击选择一个文件,打开的文件对话框将关闭(这很好),但除此之外,单击的文件后面的图像会收到一条 LeftButtonUp 消息,这根本不好。
我正在使用 wpf/c#/vs2010
I have few images in a grid, then when i click a button, a "open file dialog" comes up.(of course, over the images)
Microsoft.Win32.OpenFileDialog dlgOpenFiles = new Microsoft.Win32.OpenFileDialog();
dlgOpenFile.DoModal();
The images have a LeftButtonUp event attached. The problem is that if i select a file by double clicking it, the open file dialog closes(which is good), but besides that, the image behind the clicked file is receiving a LeftButtonUp message which is not good at all.
I am using wpf/c#/vs2010
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解决这个问题的简单方法是,每当您需要处理按钮向上事件时,添加按钮向下事件,然后在其中执行
CaptureMouse()
。现在,在按钮弹起事件中,您可以忽略所有在没有IsMouseCaptured
的情况下发生的事件。并确保不要忘记ReleaseMouseCapture()
:The simple way to get around it, is whenever you need a handler to button-up event, add a button-down event, do
CaptureMouse()
in it. Now in your button-up event you can ignore all events, which happen withoutIsMouseCaptured
. And make sure not to forgetReleaseMouseCapture()
:12 年后...
repka 的答案(上面)在 WPF UserControl 实现中对我不起作用,但它让我走上了正确的道路。相同的概念,只是使用 bool 变量而不是 CaptureMouse()。到目前为止,测试结果呈阳性。
谢谢雷普卡!
例子:
12 years later...
repka's answer (above) didn't work for me in a WPF UserControl implementation, but it got me going down the right path. Same concept, just using a bool variable instead of CaptureMouse(). So far, testing has been positive.
Thanks repka!
Example: