Articles in this section
Category / Section

How to update the ItemsSource collection using default editor in WPF Scheduler?

2 mins read

How to update the ItemsSource collection using default editor?

 

You can update the local appointment collection by using the editor events in SfSchedule control. This article explains about how to update the local appointment collection by using default editor.

Updating the local appointment collection using default editor

  1. Create a WPF application and add the SfSchedule control to it.

XAML

<syncfusion:SfSchedule x:Name="sched" ScheduleType="Month" >
 </syncfusion:SfSchedule>
  1. Create class for declaring custom appointment properties. For listening the properties dynamically, implement the property contained class in INotifyPropertyChanged interface as in the following code example.

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));
            }
        }
 
 
  1. Create local appointment collection. For listening the collection dynamically, use ObservableCollection as in the following code example.

C#

   private ObservableCollection<clsAppointment> m_Source = new         ObservableCollection<clsAppointment>();
        public ObservableCollection<clsAppointment> Source
        {
            get { return m_Source; }
            set { m_Source = value; }
        }
  1. Now create AppointmentEditorClosed event that is based on the “e.Action” value of the event argument, where you can perform your actions by setting “e.Handled” as true to avoid the default action done by the editor. Refer to the following code example.

C#

private void sched_AppointmentEditorClosed(object sender, AppointmentEditorClosedEventArgs e)
        {
            if (e.Action == EditorClosedAction.Save)
            {
                if (e.IsNew)
                {
                    AddNewClsAppointment(e.EditedAppointment);
                }
            }
            if (e.Action == EditorClosedAction.Delete)
            {
                RemoveClsAppointment(e.OriginalAppointment);
            }
            e.Handled = true;
        }
        private void AddNewClsAppointment(object appointment)
        {
             if (appointment is clsAppointment)
            {
                var scheduleAppointment = appointment as clsAppointment;
               Source.Remove(scheduleAppointment);
            }        
       }
private void RemoveClsAppointment(object appointment)
        {
          if (appointment is clsAppointment)
            {
                var scheduleAppointment = appointment as clsAppointment;
               Source.Remove(scheduleAppointment);
            }        
      }
        private static void UpdateClsAppointment(ScheduleAppointment scheduleAppointment, SfSchedule_AppointmentClass.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 e.OriginalAppointment value, you can update the custom appointment collection.

 

  1. Now create the ScheduleAppointmentMapping as in the following code example.

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 and Delete an appointment using Appointment Editor.

Sample

 

SfSchedule_AppointmentClass

 

Conclusion

I hope you enjoyed learning about how to update the ItemsSource collection using default editor in WPF Scheduler.

You can refer to our WPF Scheduler feature tour page to know about its other groundbreaking feature representations. You can also explore our WPF Scheduler documentation to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments
Please sign in to leave a comment
Access denied
Access denied