Articles in this section
Category / Section

How to bind events in Xamarin.Forms Calendar (SfCalendar) using FreshMVVM framework

1 min read

The SfCalendar 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 CalendarXamarin
{
    public partial class CalendarPage : ContentPage
    {
         public CalendarPage ()
         {
  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.

namespace CalendarXamarin
{
     public class CalendarPageModel : FreshBasePageModel
     {
        
     }
}

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

public class CalendarPageModel : FreshBasePageModel
{
      private CalendarEventCollection appointments;
 
      public CalendarEventCollection Appointments
      {
           get
           {
                return this.appointments;
           }
           set
           {
                this.appointments = value;
                this.RaisePropertyChanged("Appointments");
           }
      }
 
      public CalendarPageModel()
      {
           this.Appointments = new CalendarEventCollection();
      }
}

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

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

Step 5: Bind the event collection to the Calendar DataSource without mentioning the binding context.

<syncfusion:SfCalendar x:Name="calendar" 
                               DataSource="{Binding Appointments}" 
                               ShowInlineEvents="True"/>

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