This is a migrated thread and some comments may be shown as answers.

Drag and drop from list box to RadSchedule view through commands

1 Answer 141 Views
ScheduleView
This is a migrated thread and some comments may be shown as answers.
bonDaviD
Top achievements
Rank 1
bonDaviD asked on 15 Dec 2011, 10:27 AM
Hi,

I am trying to implement the drag and drop functionality between the RadScheduleView and listbox. I have followed the samples provided by telerik to implement the task. I have a converter named "ScheduleViewToAppointmentConverter" and also ScheduleVIewDragDropBehaviour class to implement the custom drag drop behaviour. In the Beaviour class i have override the Drop method and there i got my custom appointment Deal though State. And i can add it to the destination source and the new dragged item will be displayed in my schedule view. The code snippet for the behaviour class is as follow . Here eventhogh i get the dragged data in the drop menthod i coudnt communicate with the view model.


public class ScheduleViewDragDropBehavior : Telerik.Windows.Controls.ScheduleViewDragDropBehavior
   {
       public override IEnumerable<IOccurrence> ConvertDraggedData(object data)
       {
           if (DataObjectHelper.GetDataPresent(data, typeof(Deal), false))
           {
               return ((IEnumerable)DataObjectHelper.GetData(data, typeof(Deal), false)).OfType<IOccurrence>();
           }
           return base.ConvertDraggedData(data);
       }
 
 
       public override void Drop(Telerik.Windows.Controls.DragDropState state)
       {
           if (state.SourceAppointmentsSource == state.DestinationAppointmentsSource)
           {
               base.Drop(state);
           }
           else
           {
               var appointmentToAdd = state.Appointment as Deal;
               appointmentToAdd.Subject = "Boney";
               appointmentToAdd.Start = state.DestinationSlots.First().Start;
               appointmentToAdd.End = state.DestinationSlots.First().End;
               (state.DestinationAppointmentsSource as ObservableCollection<Deal>).Add(appointmentToAdd);
           }
       }
        
   }

Here Deal is my custom appointment class.

Now i want to implement the drag and drop through commands, so that i can get the dragged data in the view model  and from there I can assign it to the appointment collection for binding to schedule view after checking some validations. How can i implement the drag and drop though commands.?

Also i  have 2  resource named "Main" and "Side" in the schedule view. If i am dragging it main ,  I have check whether the any appointment already exists there , if so drop cannot happen So which is the best place to implement these kind of validations .

1 Answer, 1 is accepted

Sort by
0
Valeri Hristov
Telerik team
answered on 20 Dec 2011, 11:25 AM
Hi,

Regarding the drag-drop with commands: you could create ICommand dependency properties on your custom drag-drop behavior (it is a DependencyObject) and bind them to the corresponding properties in the ViewModel. The behavior inherits the data context of RadScheduleView so the binding should not be a problem.

As for the validation, I would recommend using the CanDrop method of the drag-drop behavior - if you return false the cursor will change accordingly and the experience will be consistent.

Kind regards,
Valeri Hristov
the Telerik team

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

Tags
ScheduleView
Asked by
bonDaviD
Top achievements
Rank 1
Answers by
Valeri Hristov
Telerik team
Share this question
or