We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to add additional attributes for your appointments ?

Platform: Xamarin.Forms |
Control: SfSchedule

 

In SfSchedule, you can add additional attributes for your appointments. You need to create a separate class which inherits from ScheduleAppointment and include required properties in this class for adding additional attribute to appointment. In this section, additional attribute (Appointment ID) is added to an appointment.

 

C#

        
    public class CustomAppointment : ScheduleAppointment
    {
        private string appointment_ID;
        public string AppointmentID
        {
            get { return appointment_ID; }
            set { appointment_ID = value; }
        } 
    }
 

 

C#

            
            public ObservableCollection<CustomAppointment> appointmentCollection { get ; set; }
     
           public ScheduleViewModel()
           {
            CustomAppointment  scheduleAppointment = new CustomAppointment();
            scheduleAppointment.Subject = "Meeting";            scheduleAppointment.AppointmentID = "579";
            scheduleAppointment.Color = Color.Green;
            scheduleAppointment.StartTime = DateTime.Now.Date.AddHours(10);
            scheduleAppointment.EndTime = DateTime.Now.Date.AddHours(12);
            AppointmentCollection = new ObservableCollection<CustomAppointment>();
            AppointmentCollection.Add(scheduleAppointment);
           } 
   
 

 

XAML

  
     <syncfusion:SfSchedule
       x:Name="schedule" ScheduleView="WeekView" 
       DataSource = "{Binding AppointmentCollection}" 
       HorizontalOptions="FillAndExpand"  
       VerticalOptions="FillAndExpand" >
      </syncfusion:SfSchedule>
 

 

 

In the CellTapped event of Schedule, you can get the appointment information along with additional attribute included in the argument of the event.

 

 

            
         schedule.CellTapped += CellTappedEventHandler;
 
        void CellTappedEventHandler(object sender, CellTappedEventArgs e)
        {
           var appointment = e.Appointment as CustomAppointment;
           if(appointment != null && appointment.Subject == "Meeting")
                DisplayAlert("Appointment details", appointment.AppointmentID, "ok");
        }
 

 

You can download the complete project from here ScheduleSample.

 

The following screenshot displays the output of the mentioned project.

 

added additional attributes in Schedular

2X faster development

The ultimate Xamarin UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment
Comments
Romulo Mendivil
Aug 03, 2016

What is the definition of m_source and shouldn't the custom appointment go to the AppointmentCollection?
 m_Source.Add(customAppointment);

I've been trying to pass a custom appointment to the schedule, my class definition is basically the same as the example except my field is just id instead of appointment_id. 

All seems to work ok except when in ScheduleCellTapped I am getting an 'InvalidCastException' when I try to cast it to the custom type,

CustomAppointment appointment = (CustomAppointment)args.selectedAppointment; 

Not sure if I am missing something here or am I doing something wrong? 

Reply
Romulo Mendivil
Aug 03, 2016
It seems I had some of my references incorrect / loading old versions and new version of different dlls, which I think was causing weird issues. 

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile