按住鼠标的 WPF 日历控件 [英] WPF Calendar Control holding on to the Mouse

查看:20
本文介绍了按住鼠标的 WPF 日历控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我在 VS2010 的全新 WPF 应用程序中删除了 MainWindow.xaml 上的标准 WPF Calendar 控件.如果我单击日历中的某一天,然后尝试单击应用程序的关闭按钮,我必须在关闭按钮上单击两次才能接受单击.就好像 Calendar 没有释放鼠标来与应用程序的其余部分进行交互一样.

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.

我已将 Focusable 更改为 false,但效果没有任何变化,我已尝试覆盖 PreviewOnMouseUp 并调用 ReleaseMouseCapture() 无济于事.我对 MouseLeaveMouseLeftButtonUp 做了同样的事情,结果相同.鉴于这些事情都不起作用,我怀疑我在叫错树.谷歌没有发现任何值得注意的东西,但也许我的 GoogleFu 今天还达不到标准.

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.

有什么想法吗?

推荐答案

您可以通过使用如下处理程序订阅日历的 PreviewMouseUp 事件来更改此行为:

You can change this behavior by subscribing to the calendar's PreviewMouseUp event with a handler like this:

private void Calendar_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
    if (Mouse.Captured is CalendarItem)
    {
        Mouse.Capture(null);
    }
}

这篇关于按住鼠标的 WPF 日历控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆