Articles in this section
Category / Section

How to navigate to the specific month in Xamarin.Forms Calendar (SfCalendar)

1 min read

Visible dates can be moved to specific date using MoveToDate property available in SfCalendar. It is applicable for all the ViewMode.

STEP 1: Create a ViewModel class and add a MoveToDate property with specific date.

public class ViewModel : INotifyPropertyChanged
{
   public event PropertyChangedEventHandler PropertyChanged;
 
   private DateTime moveToDate = new DateTime(2010, 10, 12);
 
   public DateTime MoveToDate
   {
     get
     {
          return this.moveToDate;
     }
     set
     {
          this.moveToDate = value;
          this.OnPropertyChanged("MoveToDate");
     }
   }
 
   public ViewModel()
   {
   }
 
   private void OnPropertyChanged(string propertyName)
   {
                this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
   }
}

STEP 2: Bind the MoveToDate ViewModel property to the MoveToDate property of SfCalendar.

<calendar:SfCalendar x:Name="calendar"
                             DataSource="{Binding Appointments}"
                             MoveToDate="{Binding MoveToDate}">
            <calendar:SfCalendar.BindingContext>
                <local:ViewModel/>
            </calendar:SfCalendar.BindingContext>
</calendar:SfCalendar>

 

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.

Output

MovetoDate

 

View sample in GitHub

 

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied