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

How can I save the color of schedule?

It's not saving the AppointmentBackground on export or maybe import is wrong?? What am I missing here? How can I save the appointment background on schedule.ExportICS() and respectively import schedule with correct background colors for each appointment?

if (panel is SfScheduler)

            {

                SfScheduler scheduler = panel as SfScheduler;

                Syncfusion.UI.Xaml.Schedule.SfSchedule schedule = new Syncfusion.UI.Xaml.Schedule.SfSchedule();


                foreach (var appointment in (ScheduleAppointmentCollection)scheduler.ItemsSource)

                {

                    try

                    {

                        Brush appointmentBackgroundColor = appointment.AppointmentBackground as Brush;

                        schedule.Appointments.Add(new Syncfusion.UI.Xaml.Schedule.ScheduleAppointment()

                        {

                            StartTime = appointment.StartTime,

                            EndTime = appointment.EndTime,

                            Subject = appointment.Subject,

                            Location = appointment.Location,

                            AllDay = appointment.IsAllDay,

                            Notes = appointment.Notes,

                            IsRecursive = string.IsNullOrEmpty(appointment.RecurrenceRule) ? false : true,

                            RecurrenceRule = appointment.RecurrenceRule ?? "",

                            AppointmentBackground = appointmentBackgroundColor,

                        });


                    }

                    catch (Exception ex)

                    {

                        string message = $"An exception occurred: {ex.ToString()}";

                        MessageBox.Show(message, "Error", (MessageBoxButton)System.Windows.Forms.MessageBoxButtons.OK, (MessageBoxImage)System.Windows.Forms.MessageBoxIcon.Error);

                    }

                }

                schedule.ExportICS();

            }




private void importSchedule_ItemClick(object sender, RoutedEventArgs e)

        {

            Syncfusion.UI.Xaml.Schedule.SfSchedule schedule = new Syncfusion.UI.Xaml.Schedule.SfSchedule();

            ScheduleAppointmentCollection events = new ScheduleAppointmentCollection();


            schedule.ImportICS();


            if (schedule != null)

            {

                SfScheduler scheduler = new SfScheduler();

                scheduler.ViewType = SchedulerViewType.Month;

                DockingManager dockingManager = DockManager;


                foreach (var appointment in schedule.Appointments)

                {

                    try

                    {

                        Brush appointmentBackgroundColor = appointment.AppointmentBackground as Brush;

                        events.Add(new Syncfusion.UI.Xaml.Scheduler.ScheduleAppointment()

                        {

                            StartTime = appointment.StartTime,

                            EndTime = appointment.EndTime,

                            Subject = appointment.Subject,

                            Location = appointment.Location,

                            IsAllDay = appointment.AllDay,

                            Notes = appointment.Notes,

                            RecurrenceRule = appointment.RecurrenceRule ?? "",

                            AppointmentBackground = appointmentBackgroundColor,

                        });

                    }

                    catch (Exception ex)

                    {

                        string message = $"An exception occurred: {ex}";

                        MessageBox.Show(message, "Error", (MessageBoxButton)System.Windows.Forms.MessageBoxButtons.OK, (MessageBoxImage)System.Windows.Forms.MessageBoxIcon.Error);

                    }

                }

                string screenName = "Scedule";

                scheduler.ItemsSource = events;

                scheduler.Name = screenName;

                DockingManager.SetHeader(scheduler, screenName);

                dockingManager.UseDocumentContainer = true;

                DockingManager.SetState(scheduler, DockState.Document);

                dockingManager.Children.Add(scheduler);

            }

        }


1 Reply

SS SaiGanesh Sakthivel Syncfusion Team April 3, 2023 10:42 AM UTC

Hi Haider,


We have adhered to the iCalendar standard for exporting iCS files from the schedule control. As the iCalendar standard does not include the background of the appointment in the file, we do not export the background of the appointment in our control. We suggest that you manually like, set the appointment's color based on its subject name at the sample level. Please refer to the following iCalendar standard link for your reference.


Link: https://en.wikipedia.org/wiki/ICalendar


Please let us know if you have any concerns.


Loader.
Live Chat Icon For mobile
Up arrow icon