diff --git a/src/MahApps.Metro/Controls/TimePicker/DateTimePicker.cs b/src/MahApps.Metro/Controls/TimePicker/DateTimePicker.cs index fb95265367..cc777fcae0 100644 --- a/src/MahApps.Metro/Controls/TimePicker/DateTimePicker.cs +++ b/src/MahApps.Metro/Controls/TimePicker/DateTimePicker.cs @@ -148,7 +148,8 @@ public override void OnApplyTemplate() { if (_calendar != null) { - _calendar.SelectedDatesChanged -= OnSelectedDateChanged; + _calendar.SelectedDatesChanged -= OnCalendarSelectedDateChanged; + _calendar.PreviewMouseUp -= OnCalendarPreviewMouseUp; } base.OnApplyTemplate(); @@ -164,12 +165,21 @@ public override void OnApplyTemplate() _calendar.SetBinding(Calendar.FirstDayOfWeekProperty, GetBinding(FirstDayOfWeekProperty)); _calendar.SetBinding(Calendar.IsTodayHighlightedProperty, GetBinding(IsTodayHighlightedProperty)); _calendar.SetBinding(FlowDirectionProperty, GetBinding(FlowDirectionProperty)); - _calendar.SelectedDatesChanged += OnSelectedDateChanged; + _calendar.SelectedDatesChanged += OnCalendarSelectedDateChanged; + _calendar.PreviewMouseUp += OnCalendarPreviewMouseUp; } SetDatePartValues(); } + private static void OnCalendarPreviewMouseUp(object sender, MouseButtonEventArgs e) + { + if (Mouse.Captured is CalendarItem) + { + Mouse.Capture(null); + } + } + protected override void OnPopUpOpened() { if (this._calendar != null) @@ -269,7 +279,7 @@ private static void OnClockVisibilityChanged(DependencyObject d, DependencyPrope d.CoerceValue(OrientationProperty); } - private static void OnSelectedDateChanged(object sender, SelectionChangedEventArgs e) + private static void OnCalendarSelectedDateChanged(object sender, SelectionChangedEventArgs e) { var dateTimePicker = (DateTimePicker)((Calendar)sender).TemplatedParent;