Bug when using custom appointments

2 posts, 0 answers
  1. hwsoderlund
    hwsoderlund avatar
    419 posts
    Member since:
    Aug 2006

    Posted 10 Oct 2011 Link to this post

    I finally managed to recreate an obscure bug in RadScheduleView. This one deserves a few extra points, I think. :)

    Background: We have a custom appointment class which is somewhat data-heavy. Because of this we cannot load up all the data for each appointment when the Appointments collection is populated. Instead we listen to the ShowDialog event to catch when the user brings up an appointment for editing. When that happens we call BeginEdit() and initiate a service call to get the full set of data for the appointment in question. When the service call returns, we populate the appropriate fields on the appointment and call EndEdit().

    Now for the bug, which is rather obscure. Here is how to reproduce it in the sample project (link below):

    1. Double-click either one of the two appointments in the Month view.
    2. Edit the Subject.
    3. Bring focus to the Description field, or any other field except the Subject.
    4. Bug 1: When the Subject field lost focus, the window header updated immediately. This should not have happened since the appointment had not yet been saved.
    5. Click the Cancel button.
    6. Double-click the appointment again.
    Bug 2: The previous edits that should have been cancelled were in fact not cancelled at all, but remain in place in the edit dialog. However, they were _not_ commited to the Slot in the scheduleview representing the appointment.

    Maybe I am doing something wrong here. I am not entirely sure how the whole BeginEdit/EndEdit thing should be handled. But my code looks logical enough to me and I believe it should work. Please advice on possible workarounds.

    I am using the internal build from 4 October, but as far as I can see this bug has been present for quite some time. It is only very recently that we found it.

    Sample project on dropbox:

    Check out the code in the event handler for the ShowDialog event, that is where the interesting stuff happens.

    Best regards,
  2. Rosi
    Rosi avatar
    2529 posts

    Posted 11 Oct 2011 Link to this post

    Hello Hwsoderlund,

    When you double click the appointment and the dialog is opened RadScheduleView call's  the BeginEdit() method internally. That is why there is no need to call it in the ShowDialog event.

    As for the problems that you described -I review your project and the reason for them is the call of EndEdiit() method that commits the changes. If you need to cancel the changes you can call CancelEdit() method instead.

    To implement the task I suggest you update the properties before the appointment is opened. I suggest you try the code below:
    private bool showdialog = false;
    void RadScheduleView1_ShowDialog(object sender, ShowDialogEventArgs e)
        if (!showdialog)
            var vm = e.DialogViewModel;
            var avm = vm as AppointmentDialogViewModel;
            if (avm != null)
                var app = avm.Occurrence.Appointment as CustomAppointment;
                (app as IAppointment).BeginEdit();
                showdialog = false;
                e.Cancel = true;//cancel opening the dialog here
                //At this point in the real app I make a service call to pick up some
                //custom data for this particular appointment.
                //Dispatching this to simulate the return of the service call.
                Dispatcher.BeginInvoke(() =>
                    //(app as IAppointment).Subject = "test";//set here the additional properties.
                    (app as IAppointment).EndEdit();
                    showdialog = true;
                    RadScheduleViewCommands.EditAppointment.Execute((app as IAppointment), RadScheduleView1);//open the dialog again.
            showdialog = false;

    Kind regards,
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top