WPF 工具包日历需要单击两次才能获得焦点

发布于 2024-08-25 03:49:51 字数 141 浏览 4 评论 0原文

我正在使用 WPF 日历,它是 WPF 工具包的一部分。

我的一个控件上有两个不同的日历。当我尝试从一个日历中选择日期,然后从第二个日历中选择日期时,我必须单击第二个日历两次才能使其选择日期。

还有其他人遇到过这个问题并知道解决方案吗?

I am using the WPF Calendar that is part of the WPF Toolkit.

I have two different calendars on a control. When I attempt to choose a date from one calendar and then from the second calendar, I have to click on the second calendar twice to get it to choose a date.

Has anyone else had this issue and know of a solution?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

热血少△年 2024-09-01 03:49:51

日历可以捕获鼠标而无需更改日期(例如,在日历模式下钻取)。
更好的解决方案是这样的:

protected override void OnPreviewMouseUp(MouseButtonEventArgs e)
{
    base.OnPreviewMouseUp(e);
    if (Mouse.Captured is CalendarItem)
    {
        Mouse.Capture(null);
    }
}

The calendar can capture the mouse without a date change (e.g. in CalendarMode drill down).
A better solution is this:

protected override void OnPreviewMouseUp(MouseButtonEventArgs e)
{
    base.OnPreviewMouseUp(e);
    if (Mouse.Captured is CalendarItem)
    {
        Mouse.Capture(null);
    }
}
锦欢 2024-09-01 03:49:51

我在更改日历的 SelectedDates 时添加了此代码,它解决了问题。

        Private Sub Calendar_SelectedDatesChanged(ByVal sender As Object, ByVal e As System.Windows.Controls.SelectionChangedEventArgs) Handles Me.SelectedDatesChanged
        Me.DisplayDate = CType(Me.SelectedDate, DateTime)

        ' This is to prevent the Calendar DayButtons from holding the focus in the Calendar.
        Me.CaptureMouse()
        Me.ReleaseMouseCapture()
    End Sub

I added this code when changing the SelectedDates of the Calendar and it fixed the issue.

        Private Sub Calendar_SelectedDatesChanged(ByVal sender As Object, ByVal e As System.Windows.Controls.SelectionChangedEventArgs) Handles Me.SelectedDatesChanged
        Me.DisplayDate = CType(Me.SelectedDate, DateTime)

        ' This is to prevent the Calendar DayButtons from holding the focus in the Calendar.
        Me.CaptureMouse()
        Me.ReleaseMouseCapture()
    End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文