You can update the local appointment collection by using the editor events in the SfSchedule control. This article explains how to update the local appointment collection by using the default editor. Updating the local appointment collection by using the default editor:
XAML <syncfusion:SfSchedule x:Name="sched" ScheduleType="Month" > </syncfusion:SfSchedule>
C# public class clsAppointment : INotifyPropertyChanged { private bool m_AllDay; public bool AllDay { get { return m_AllDay; } set { m_AllDay = value; OnPropertyChanged("AllDay"); } } private System.DateTime m_EndDateTime; public System.DateTime EndDateTime { get { return m_EndDateTime; } set { m_EndDateTime = value; OnPropertyChanged("EndDateTime"); } } private string m_Location; public string Location { get { return m_Location; } set { m_Location = value; OnPropertyChanged("Location"); } } private string m_Notes; public string Notes { get { return m_Notes; } set { m_Notes = value; OnPropertyChanged("Notes"); } } private System.DateTime m_StartDateTime; public System.DateTime StartDateTime { get { return m_StartDateTime; } set { m_StartDateTime = value; OnPropertyChanged("StartDateTime"); } } private string m_Subject; public string Subject { get { return m_Subject; } set { m_Subject = value; OnPropertyChanged("Subject"); } } public event PropertyChangedEventHandler PropertyChanged; private void OnPropertyChanged(string propertyName) { var eventHandler = this.PropertyChanged; if (eventHandler != null) eventHandler(this, new PropertyChangedEventArgs(propertyName)); } }
C# private ObservableCollection<clsAppointment> m_Source = new ObservableCollection<clsAppointment>(); public ObservableCollection<clsAppointment> Source { get { return m_Source; } set { m_Source = value; } }
C# private void sched_AppointmentEditorClosed(object sender, AppointmentEditorClosedEventArgs e) { if (e.Action == EditorClosedAction.Save) { if (e.IsNew) { AddNewClsAppointment(e.EditedAppointment); } else { EditClsAppointment(e.EditedAppointment); } } if (e.Action == EditorClosedAction.Delete) { RemoveClsAppointment(e.OriginalAppointment); } e.Handled = true; } private void EditClsAppointment(object appointment) { if(appointment is ScheduleAppointment) { var scheduleAppointment = appointment as ScheduleAppointment; //Since the appointment's ObjectID is equal to the hashCode value of the corresponding CustomClass object in the ItemsSource, based on it, the corresponding item is updated. var clsAppointment = Source.FirstOrDefault(app => app.GetHashCode() == scheduleAppointment.ObjectID); UpdateClsAppointment(scheduleAppointment, clsAppointment); } } private void AddNewClsAppointment(object appointment) { if(appointment is ScheduleAppointment) { var scheduleAppointment = appointment as ScheduleAppointment; var clsAppointment = new clsAppointment(); UpdateClsAppointment(scheduleAppointment, clsAppointment); Source.Add(clsAppointment); } } private void RemoveClsAppointment(object appointment) { if (appointment is ScheduleAppointment) { var scheduleAppointment = appointment as ScheduleAppointment; //Since the appointment's ObjectID is equal to the hashCode value of the corresponding CustomClass object in ItemsSource, based on it, the corresponding item is updated. var clsAppointment = Source.FirstOrDefault(app => app.GetHashCode() == scheduleAppointment.ObjectID); Source.Remove(clsAppointment); } } private static void UpdateClsAppointment(ScheduleAppointment scheduleAppointment, LocalAppointmentCollection_WinRT.clsAppointment clsAppointment) { clsAppointment.Subject=scheduleAppointment.Subject; clsAppointment.AllDay = scheduleAppointment.AllDay; clsAppointment.Location = scheduleAppointment.Location; clsAppointment.Notes = scheduleAppointment.Notes; clsAppointment.StartDateTime = scheduleAppointment.StartTime; clsAppointment.EndDateTime = scheduleAppointment.EndTime; } In the above code example, by using the e.EditedAppointment and the e.OriginalAppointment value, you can update the custom appointment collection.
XAML <syncfusion:SfSchedule.AppointmentMapping> <syncfusion:ScheduleAppointmentMapping SubjectMapping="Subject" NotesMapping="Notes" LocationMapping="Location" StartTimeMapping="StartDateTime" EndTimeMapping="EndDateTime" AllDayMapping="AllDay" /> </syncfusion:SfSchedule.AppointmentMapping> After completing the above steps, run the project and the local appointment collection gets updated when you Add, Edit, or Delete an appointment. Use the Edit option in the context menu to edit or delete appointments.
|
This page will automatically be redirected to the sign-in page in 10 seconds.