Skip to content

This repository contains a sample on How to initialize the selected date in the Syncfusion Xamarin.Forms Calendar (SfCalendar)?

Notifications You must be signed in to change notification settings

SyncfusionExamples/selected-date-binding-calendar-xamarin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

How to programatically change the selected date in Xamarin.Forms Calendar (SfCalendar)

Initially, the calendar is loaded with the current day as selected date and you can initialize the calendar with specific date by using SelectedDate property in SfCalendar.

You can also refer the following article.

https://www.syncfusion.com/kb/11799/how-to-programatically-change-the-selected-date-in-xamarin-forms-calendar-sfcalendar

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

public class ViewModel : INotifyPropertyChanged
{
            public event PropertyChangedEventHandler PropertyChanged;
 
            private DateTime selectedDate = DateTime.Now.AddDays(5);
 
            public DateTime SelectedDate
            {
                get
                {
                    return this.selectedDate;
                }
                set
                {
                    this.selectedDate = value;
                    this.OnPropertyChanged("SelectedDate");
                }
            }
 
            public ViewModel()
            {
            }
 
            private void OnPropertyChanged(string propertyName)
            {
                this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
            }
}

STEP 2: Bind the SelectedDate ViewModel property to the SelectedDate property in SfCalendar.

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

Output

SelectedDateCalendar

About

This repository contains a sample on How to initialize the selected date in the Syncfusion Xamarin.Forms Calendar (SfCalendar)?

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages