Edit 2: Thank you all for your feedback. I solved the problem by adding this to my SelectedDatesChanged event:
Mouse.Capture(null);
When I select a
Releasing all mouse clicks in SelectedDatesChanged
or GotMouseCapture
will break the navigation between months on the calendar control. As pointed out in another answer, SelectedDatesChanged
does not fire when the same date is selected.
So I used GotMouseCapture
and only released the mouse focus when the clicked UIElement was a calendar day. It fixes the focus issue and doesn't break the rest of the control.
private void Calendar_GotMouseCapture(object sender, MouseEventArgs e)
{
UIElement originalElement = e.OriginalSource as UIElement;
if (originalElement is CalendarDayButton || originalElement is CalendarItem)
{
originalElement.ReleaseMouseCapture();
}
}