Appointment: validate changes during drag&drop

4 posts, 1 answers
  1. Björn
    Björn avatar
    23 posts
    Member since:
    Mar 2011

    Posted 13 Feb 2012 Link to this post

    I want to check, if a user can Drag&Drop an appointment to a new date.
    For that I catch in OnAppointmentEditingCommand the AppointmentEditedEventArgs
    and set the e.Cancel=true, if it's not allowed.
    To validate the changes, I need the orginal and changed data - but the changed data are missing!
    Where can I find in the AppointmentEditedEventArgs the changed data?

    We display in the scheduler different calendars (resources). It's not allowed to drag&drop an appointment to another calendar.
    Need for that the changed resources collection in AppointmentEditedEventArgs or what to do?

    Other way to check the values is in the OnAppointmentEditedCommand.
    Then I have to remember the orginal state before and compare that with the values in AppointmentEditedEventArgs.
    But To cancel the changes, it's not possible to use  e.Handled = false;
    What's the idea of the e.Handled?

    Thanks for help.
  2. Answer
    Valeri Hristov
    Valeri Hristov avatar
    2252 posts

    Posted 16 Feb 2012 Link to this post

    Hello Bjorn,

    For drag-drop validation I would recommend using a custom ScheduleViewDragDropBehavior and checking the validity of the operation in the CanDrop method. You have access to the original appointments in the state.DraggedAppointments collection and to the properties that will be applied in the state.DestinationSlots collection. With this approach you should be easily able to accomplish all three tasks.

    The ScheduleViewDragDropBehavior class inherits from DependencyObject so you should be able to add dependency properties and bind them to your view model if needed.

    All the best,
    Valeri Hristov
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. Predrag
    Predrag avatar
    13 posts
    Member since:
    Oct 2011

    Posted 30 Mar 2012 Link to this post

    Hi Valeri,


    I’m using custom ScheduleViewDragDropBehavior and I would like to do the validation on Drop. For this I need my ViewModel, so I tried to create ICommand dependency properties on my custom drag-drop behavior and bind them to the corresponding properties in the ViewModel. I have problem it seems that ScheduleViewDragDropBehavior is NOT a DependencyObject. I managed to get ViewModel using:

    var scheduleView = state.ServiceProvider.GetService<IObjectEditor<IAppointment>>() as RadScheduleView;

    And than scheduleView.DataContext property.
    This is workaround is it possible to bind ScheduleViewDragDropBehavior to the ViewModel?

    Thanks for help.

  4. Miroslav Nedyalkov
    Miroslav Nedyalkov avatar
    1718 posts

    Posted 04 Apr 2012 Link to this post

    Hi Predrag,

    The default DragDropBehavior is not a DependencyObject as it is designed to be shared between many ScheduleViews and because of this it should be stateless. What I would suggest you is to either your work-around or to create a property for the ViewModel at your custom behavior and set it once the page is initialized.

    Hope this helps.

    Kind regards,
    Miroslav Nedyalkov
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Back to Top