Skip to content

Commit

Permalink
(MahAppsGH-3746) Fix capturing CalendarItem
Browse files Browse the repository at this point in the history
  • Loading branch information
punker76 committed Apr 21, 2020
1 parent b70a950 commit 21ac235
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/MahApps.Metro/Controls/TimePicker/DateTimePicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ public override void OnApplyTemplate()
{
if (_calendar != null)
{
_calendar.SelectedDatesChanged -= OnSelectedDateChanged;
_calendar.SelectedDatesChanged -= OnCalendarSelectedDateChanged;
_calendar.PreviewMouseUp -= OnCalendarPreviewMouseUp;
}

base.OnApplyTemplate();
Expand All @@ -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)
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 21ac235

Please sign in to comment.