Hi, I’m having trouble implementing drag & drop of custom appointments into RadScheduleView and would be thankful if anyone could point me in the right direction.
I have a ListBox (standard WPF} which contains some items (files to be played). User can drag these items and place them onto RadSchedule (play time). I figured out how to enable dragging and transform the data into Appointment. I can see the created item when it’s being dragged over schedule view, but when I release the mouse /Drop/ nothing happens.
Item is not added to bound Appointments collection, nor is any *Drop event being raised. I should note there is a “Forbidden” mouse cursor icon when dragging.
When I drag
& resize appointments, that are already present in collection, everything
works as expected.
I was even
able to reproduce it with this simplified example:
public class MainWindowViewModel { public MainWindowViewModel() { appointments.Add( new Appointment() { Start = DateTime.Now, End = DateTime.Now.AddHours(1), Subject = "Test" }); } //ItemsSource for listbox private ObservableCollection<string> strings = new ObservableCollection<string>() { "First", "Second", "Third" }; public ObservableCollection<string> Strings { get { return strings; } set { strings = value; } } //ItemsSource for RadSceduleView private ObservableCollection<Appointment> appointments = new ObservableCollection<Appointment>(); public ObservableCollection<Appointment> Appointments { get { return appointments; } set { appointments = value; } } }
Behavior to transform dragged string into appointment collection:
public class DropBehavior : ScheduleViewDragDropBehavior { public override IEnumerable<IOccurrence> ConvertDraggedData(object data) { if (Telerik.Windows.DragDrop.Behaviors.DataObjectHelper.GetDataPresent(data, typeof(ListBoxItem), false)) { var lbItem = Telerik.Windows.DragDrop.Behaviors.DataObjectHelper.GetData(data, typeof(ListBoxItem), false) as ListBoxItem; return new Appointment[] { new Appointment() { Subject = (string)lbItem.DataContext } }; }; return base.ConvertDraggedData(data); } }
And final XAML:
<Window x:Class="ScheduleViewTest.MainWindow" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" xmlns:local="clr-namespace:ScheduleViewTest" Title="MainWindow" Width="640" Height="480"> <Window.DataContext> <local:MainWindowViewModel/> </Window.DataContext> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition/> <ColumnDefinition Width="15"/> <ColumnDefinition Width="3*"/> </Grid.ColumnDefinitions> <ListBox ItemsSource="{Binding Strings}"> <ListBox.ItemContainerStyle> <Style TargetType="ListBoxItem"> <Setter Property="telerik:DragDropManager.AllowCapturedDrag" Value="True"/> </Style> </ListBox.ItemContainerStyle> </ListBox> <telerik:RadScheduleView x:Name="scheduler" Grid.Column="2" AllowDrop="True" AppointmentsSource="{Binding Appointments}"> <telerik:RadScheduleView.ViewDefinitions> <telerik:DayViewDefinition/> <telerik:MonthViewDefinition/> </telerik:RadScheduleView.ViewDefinitions> <telerik:RadScheduleView.DragDropBehavior> <local:DropBehavior/> </telerik:RadScheduleView.DragDropBehavior> </telerik:RadScheduleView> </Grid></Window>
As for version I'm using "2013.2.611.45" and preferably would like to avoid updating (legacy app)
Thanks for help and suggestions in advance.
Matej