Skip to content

Commit

Permalink
(MahAppsGH-3746) Add DisplayDateChanged event handling
Browse files Browse the repository at this point in the history
  • Loading branch information
punker76 committed Apr 21, 2020
1 parent 1b81b90 commit d669fab
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/MahApps.Metro/Controls/TimePicker/DateTimePicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public override void OnApplyTemplate()
if (_calendar != null)
{
_calendar.PreviewKeyDown -= this.CalendarPreviewKeyDown;
_calendar.DisplayDateChanged -= this.CalendarDisplayDateChanged;
_calendar.SelectedDatesChanged -= CalendarSelectedDateChanged;
_calendar.PreviewMouseUp -= CalendarPreviewMouseUp;
}
Expand All @@ -161,6 +162,7 @@ public override void OnApplyTemplate()
if (_calendar != null)
{
_calendar.PreviewKeyDown += this.CalendarPreviewKeyDown;
_calendar.DisplayDateChanged += this.CalendarDisplayDateChanged;
_calendar.SelectedDatesChanged += CalendarSelectedDateChanged;
_calendar.PreviewMouseUp += CalendarPreviewMouseUp;

Expand All @@ -184,6 +186,14 @@ private static void CalendarPreviewMouseUp(object sender, MouseButtonEventArgs e
}
}

private void CalendarDisplayDateChanged(object sender, CalendarDateChangedEventArgs e)
{
if (e.AddedDate is DateTime addedDate && addedDate != this.DisplayDate)
{
SetCurrentValue(DisplayDateProperty, addedDate);
}
}

private void CalendarPreviewKeyDown(object sender, RoutedEventArgs e)
{
var calendar = sender as Calendar;
Expand Down

0 comments on commit d669fab

Please sign in to comment.