diff --git a/src/Calendar.Plugin/Shared/Controls/Calendar.xaml.cs b/src/Calendar.Plugin/Shared/Controls/Calendar.xaml.cs index 855858f..d90facc 100644 --- a/src/Calendar.Plugin/Shared/Controls/Calendar.xaml.cs +++ b/src/Calendar.Plugin/Shared/Controls/Calendar.xaml.cs @@ -1235,22 +1235,38 @@ private int GetWeekNumber(DateTime date) private void PrevUnit() { - ShownDate = _viewLayoutEngine.GetPreviousUnit(ShownDate); + var targetDate = _viewLayoutEngine.GetPreviousUnit(ShownDate); + + ShownDate = targetDate < MinimumDate + ? MinimumDate + : targetDate; } private void NextUnit() { - ShownDate = _viewLayoutEngine.GetNextUnit(ShownDate); + var targetDate = _viewLayoutEngine.GetNextUnit(ShownDate); + + ShownDate = targetDate > MaximumDate + ? MaximumDate + : targetDate; } - private void NextYear(object obj) + private void PrevYear(object obj) { - ShownDate = ShownDate.AddYears(1); + var targetDate = ShownDate.AddYears(-1); + + ShownDate = targetDate < MinimumDate + ? MinimumDate + : targetDate; } - private void PrevYear(object obj) + private void NextYear(object obj) { - ShownDate = ShownDate.AddYears(-1); + var targetDate = ShownDate.AddYears(1); + + ShownDate = targetDate > MaximumDate + ? MaximumDate + : targetDate; } private void ToggleCalendarSectionVisibility()