views:

359

answers:

2

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?

+1  A: 

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
timothymcgrath
The Me.DisplayDate line is just to move the view to the SelectedDate, this isn't needed for the fix.
timothymcgrath
This work for me, Thank you for your solution. (C#)
Jirapong
+1  A: 

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);
    }
}
Martin