Exception with Custom Appointment Doesn't Update UI

2 posts, 0 answers
  1. heavywoody
    heavywoody avatar
    79 posts
    Member since:
    Oct 2009

    Posted 07 May 2015 Link to this post

    I am not sure if this is by design, but I noticed if I create an Exception at runtime using a Custom Appointment and change a field, it doesn't update the UI until I do something like change the View and come back.  I have found a hack where I delete the appointment and then immediately re-add it.  But is there a way to tell the UI to update after adding an Exception?  Here is some example code I made to show that on a button click, I am just creating an Exception and adding it to an Appointment. I want to change the border color.  But it doesn't change until I change the Schedule View and come back.

     

    public MainWindow()
            {
                InitializeComponent();
                DataContext = this;

                var resourceType = new ResourceType("Location") { AllowMultipleSelection = true };
                var room1 = new Resource("Room 1");
                var room2 = new Resource("Room 2");
                var room3 = new Resource("Room 3");
                resourceType.Resources.Add(room1);
                resourceType.Resources.Add(room2);
                resourceType.Resources.Add(room3);

                var groupDescription = new GroupDescriptionCollection
                {
                    new DateGroupDescription(),
                    new ResourceGroupDescription { ResourceType = "Location" }
                };

                ScheduleView.GroupDescriptionsSource = groupDescription;

                ScheduleView.ResourceTypesSource = new ResourceTypeCollection { resourceType };

                var app = new CustomeAppoinment { Start = new DateTime(2015, 05, 07, 4, 50, 00), End = new DateTime(2015, 05, 07, 6, 50, 00), Subject = "Test" };
                RecurrencePattern pattern;
                RecurrencePatternHelper.TryParseRecurrencePattern("FREQ=DAILY;COUNT=10", out pattern);
                app.RecurrenceRule = new RecurrenceRule(pattern);
                app.Resources.Add(room1);
                app.Resources.Add(room2);

                Appointments.Add(app);
                

            }

            private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
            {
                var appointment = Appointments[0].Copy();
                var customAppointment = new CustomAppointment
                {
                    Start = appointment.Start,
                    End = appointment.End,
                    RecurrenceRule = appointment.RecurrenceRule,
                    Subject = appointment.Subject,
                    IsAllDayEvent = appointment.IsAllDayEvent,
                    UniqueId = Guid.NewGuid().ToString(),
                    BorderColor = Brushes.Green
                };

                foreach (var item in appointment.Resources)
                {
                    var resource = item as Resource;
                    customAppointment.Resources.Add(resource);
                }

                Appointments[0].RecurrenceRule.AddException(Appointments[0].Start, customAppointment);

               //Workaround.  Remove and re-add the appointment to update the UI.
                var appt=Appointments[0];
        
                Appointments.Remove(appt);
                Appointments.Add(appt);

            }

     

    private ObservableCollection<CustomAppointment> _appointments = new ObservableCollection<CustomAppointment>();
            public ObservableCollection<CustomAppointment> Appointments
            {
                get { return _appointments; }
                set { _appointments = value; RaisedPropertyChanged("Appointments"); }
            }


            public event PropertyChangedEventHandler PropertyChanged;

            public void RaisedPropertyChanged(string propertyName)
            {
                PropertyChangedEventHandler handler = PropertyChanged;
                if (handler != null)
                {
                    var e = new PropertyChangedEventArgs(propertyName);
                    handler(this, e);
                }
            }

     

     

  2. Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 11 May 2015 Link to this post

    Hi  Christian,

    Thank you for contacting us.

    When an appointment or an recurrence rule is edited from the code you will need to call the BeginEdit and Commit methods of the control. This way the RadScheduleView and its appointment containers will be notified that they need to update their UI. You can take a look at our online documentation here for further details about appointment editing.

    In the context of the provided code snippet all that you need to do is replace the removing and adding of the "appt" appointment with the following code:
    var appointment = Appointments[0].Copy();
    var customAppointment = new Appointment
    {
        Start = appointment.Start,
        End = appointment.End,
        RecurrenceRule = appointment.RecurrenceRule,
        Subject = appointment.Subject + " Exception",
        IsAllDayEvent = appointment.IsAllDayEvent,
        UniqueId = Guid.NewGuid().ToString(),
    };
     
    foreach (var item in appointment.Resources)
    {
        var resource = item as Resource;
        customAppointment.Resources.Add(resource);
    }
     
    var appt = Appointments[0];
     
    // Start the editing of the appointment before you make the changes.
    this.ScheduleView.BeginEdit(appt);
     
    // Make the changes
    Appointments[0].RecurrenceRule.AddException(Appointments[0].Start, customAppointment);
     
    // Commit the changes
    this.ScheduleView.Commit();

    Hope this is helpful.

    Regards,
    Vladi
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top