Articles in this section
Category / Section

How to bind appointments in Xamarin.Forms Schedule (SfSchedule) using FreshMVVM framework

2 mins read

The SfSchedule allows you to work with FreshMvvm framework. To achieve this, follow the below steps:

Step 1: Install the FreshMvvm NuGet package in your shared code project.

Step 2: Create your XAML page (view) with name ending with “Page”.

namespace ScheduleXamarin
{
    public partial class SchedulerPage : ContentPage
    {
        public SchedulerPage()
        {
            InitializeComponent();
        }
    }
}

Step 3: Create a page model with the name ending with PageModel and inherit FreshBasePageModel. If your Page name is MainPage, then the PageModel name should be MainPageModel and the namespace of Page and PageModel should be the same. In this PageModel, you can keep the ViewModel related properties.

namespace ScheduleXamarin
{
    public class SchedulerPageModel : FreshBasePageModel
    {
        
    }
}

Step 4: To raise property changed notifier, use RaisePropertyChanged method of base class in your PageModel.

public class SchedulerPageModel : FreshBasePageModel
{
        private ObservableCollection<Meeting> meetings;
 
        public SchedulerPageModel()
        {
            this.Meetings = new ObservableCollection<Meeting>();
        }
 
        public ObservableCollection<Meeting> Meetings
        {
            get
            {
                return this.meetings;
            }
 
            set
            {
                this.meetings = value;
                this.RaisePropertyChanged("Meetings");
            }
        }
}

Step 5: Set MainPage using PageModel in your App.xaml.cs file.

public partial class App : Application
{
        public App()
        {
            InitializeComponent();
 
            var page = FreshPageModelResolver.ResolvePageModel<SchedulerPageModel>();
            var basicNavContainer = new FreshNavigationContainer(page);
            MainPage = basicNavContainer;
        }
}

Step 6: Bind the appointment collection to the Schedule DataSource without mentioning the binding context.

<schedule:SfSchedule x:Name="schedule" ScheduleView="WeekView" DataSource="{Binding Meetings}">
          <schedule:SfSchedule.AppointmentMapping>
                <schedule:ScheduleAppointmentMapping
               SubjectMapping="EventName" 
               ColorMapping="Color"
               StartTimeMapping="From"
               EndTimeMapping="To">
                </schedule:ScheduleAppointmentMapping>
         </schedule:SfSchedule.AppointmentMapping>
</schedule:SfSchedule>

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