)
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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to update the ItemsSource collection using default editor?

Platform: WPF |
Control: Tools |
Published Date: June 27, 2019 |
Last Revised Date: June 27, 2019
Tags: sfschedule

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

 

2X faster development

The ultimate WPF UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

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
Live Chat Icon