WPF 日历控件按住鼠标
因此,我在 VS2010 中的全新 WPF 应用程序中删除了 MainWindow.xaml 上的标准 WPF Calendar
控件。如果我单击日历中的某一天,然后尝试单击应用程序的“关闭”按钮,则我必须在关闭按钮上单击两次才能接受单击。它的表现就好像Calendar
尚未释放鼠标来与应用程序的其余部分进行交互。
我已将 Focusable
更改为 false,但没有任何更改,并且我尝试覆盖 PreviewOnMouseUp
并将 ReleaseMouseCapture()
调用为 no有用。我对 MouseLeave
和 MouseLeftButtonUp
做了同样的事情,得到了相同的结果。鉴于这些事情都不起作用,我怀疑我找错了对象。谷歌没有发现任何值得注意的东西,尽管也许我的 GoogleFu 今天还没有达到标准。
有什么想法吗?
So I dropped the standard WPF Calendar
control on the MainWindow.xaml in a brand new WPF App in VS2010. If I click on a day in the calendar and then try to click the Close button for the app, I have to click twice on the close button before it accepts the click. It's acting as if the Calendar
hasn't released the Mouse to interact with the rest of the application.
I've changed Focusable
to false, with no change in effect, and I've tried overriding the PreviewOnMouseUp
and calling ReleaseMouseCapture()
to no avail. I've done the same thing with MouseLeave
and MouseLeftButtonUp
with the same result. Given that none of those things are working I suspect I'm barking up the wrong tree. Google has turned up nothing of note, though perhaps my GoogleFu is not up to snuff today.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以通过使用如下处理程序订阅日历的 PreviewMouseUp 事件来更改此行为:
You can change this behavior by subscribing to the calendar's PreviewMouseUp event with a handler like this:
日历控件托管在弹出窗口中,并捕获鼠标。当您第一次单击其他位置时,捕获会将单击发送到弹出窗口,弹出窗口意识到您在其自身外部单击后会关闭。因此,单击不会转到该按钮。
使用 ComboBox 时可以看到相同的效果。将其放下,然后单击按钮。它不会点击按钮。
不幸的是,您不可能采取任何措施来改变这种行为。
编辑:.NET 的最新版本使解决方案成为可能。请参阅艾伦的回答。
The calendar control is hosted in a popup, and captures the mouse. When you click somewhere else the first time, the capture sends the click to the popup, which, realizing that you've clicked outside of itself, closes. The click therefore does not go to the button.
You can see the same effect when using a ComboBox. Drop it down, then click on a button. It won't click the button.
Unfortunately, it's unlikely you can do anything to alter this behavior.
Edit: More recent versions of .NET make a solution possible. See Eren's answer.
这是我用来解决鼠标捕获问题和子控件缺少 Click 事件的代码的基础。它可能可以进一步简化,以使日历控件更直接地访问,但我个人倾向于将其添加到 UserControl 中。
This is the basis of the code I use to work around both the mouse capture issue and the lack of Click events from child controls. It can probably be simplified further to make the calendar control more directly accessible, but I personally tend to add it into the UserControl.
这段代码一定有帮助
This code must help