RadScheduleView - Drag from ListBox

3 posts, 1 answers
  1. Matej
    Matej avatar
    2 posts
    Member since:
    Sep 2015

    Posted 07 Sep 2015 Link to this post

    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

  2. Answer
    Nasko
    Admin
    Nasko avatar
    585 posts

    Posted 08 Sep 2015 Link to this post

    Hello Matej,

    Please, check the following article from our help documentation that provides detailed information how to enable the DragDrop functionality between ListBox and RadScheduleView:
    http://docs.telerik.com/devtools/wpf/controls/dragdropmanager/behaviors/listboxandscheduleview

    The reason why the DragDrop in your solution does not work as expected is the missing set DragDropBehavior for the ListBox control:
    <ListBox ItemsSource="{Binding Strings}">
        <ListBox.ItemContainerStyle>
            <Style TargetType="ListBoxItem">
                <Setter Property="telerik:DragDropManager.AllowCapturedDrag" Value="True"/>
            </Style>
        </ListBox.ItemContainerStyle>
        <telerik:ListBoxDragDrop.Behavior>
            <telerik:ListBoxDragDropBehavior />
        </telerik:ListBoxDragDrop.Behavior>
    </ListBox>

    We hope this will help you.

    Regards,
    Nasko
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
  4. Matej
    Matej avatar
    2 posts
    Member since:
    Sep 2015

    Posted 08 Sep 2015 in reply to Nasko Link to this post

    That worked like a charm, thanks again.
Back to Top