- Programmatic Navigation
Contact Support
Date Navigation in Xamarin Calendar (SfCalendar)
8 Jan 20252 minutes to read
The SfCalendar
control provides the option to navigate through items either programmatically or by using gestures.
Programmatic Navigation
By using the following methods, we can navigate the months or year in SfCalendar
with programmatically without applying gesture.
-
Forward
-
Backward
Forward
By default, the date can be navigated to next view using touch gesture and swiping the control in right to left direction. The view can also be changed programmatically using Forward method available in SfCalendar
. It will move to next month,next year,next period of decade years,next period of century years based on the ViewMode
.
calendar.Forward();
NOTE
It can be navigated until it reaches the MaxDate.
Backward
By default, the date can be navigated to previous view using touch gesture and swiping the control in left to right direction. The view can also be changed programmatically using Backward method available in SfCalendar
. It will move to previous month,previous year,previous period of decade years,previous period century years based on the ViewMode
.
calendar.Backward();
NOTE
It can be navigated until it reaches the MinDate.
Move to Date
Visible dates can be moved to specific date using MoveToDate property available in SfCalendar
. it will move to any specific month,year,decade,century view based on the ViewMode
.
NOTE
The specified date should lie between MinDate and MaxDate, if the specified date is greater than MaxDate then the view will be moved to MaxDate and if the specified date is lesser than the MinDate then the view will be moved to MinDate.
SfCalendar calendar = new SfCalendar();
calendar.MoveToDate = new DateTime(2017,5,5);
this.Content = calendar;
Navigation Direction
You can navigate the calendar MonthView
, YearView
, DecadeView
and CenturyView
either Vertical
or Horizontal
directions by setting the NavigationDirection.
SfCalendar calendar = new SfCalendar();
Calendar.NavigationDirection = NavigationDirection.Vertical;
NavigateTo
Visible dates can be moved to a specific date using the NavigateTo method available in SfCalendar.It will move to any specific date of the month if the calendar view is Month View.
DateTime currentDate = DateTime.Now;
DateTime SpecificDate = new DateTime(currentDate.Year - 5,currentDate.Month - 3, currentDate.Day, 0, 0, 0);
calendar.NavigateTo(SpecificDate);