Getting Started with DragDrop

3 posts, 0 answers
  1. Andy
    Andy avatar
    13 posts
    Member since:
    Apr 2014

    Posted 18 Jun 2014 Link to this post

    Trying to make my first DragDrop among RadListBox working but not sure what I am missing - but I am sure that I am missing something. I just have two list boxes - one bound to available friends (from where the drag is initiated) and the other one bound to selected friends where the friends are dropped. But at this point, it just shows up as being dragged from the originating Radlistbox - but nothing comes in the other radlistbox. Pls help.
    Here is my XAML and ViewModel. How does this work? Whenever I drop a friend - then ViewModel setter is also not called. So - how actually the OtherRadListBox gets bound to the dropped values.
       
    <Window.DataContext>
        <local:MainViewModel />
    </Window.DataContext>
    <Window.Resources>
        <Style x:Key="DraggableListBoxItem" TargetType="telerik:RadListBoxItem">
            <Setter Property="telerik:DragDropManager.AllowCapturedDrag" Value="True" />
        </Style>
    </Window.Resources>
        <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <telerik:RadListBox ItemContainerStyle="{StaticResource DraggableListBoxItem}"
                            AllowDrop="True"
                            Grid.Column="0" ItemsSource="{Binding AvailableDropZones}" DisplayMemberPath="Name">
            <telerik:RadListBox.DragDropBehavior>
                <telerik:ListBoxDragDropBehavior />
            </telerik:RadListBox.DragDropBehavior>
        </telerik:RadListBox>
        <telerik:RadListBox ItemsSource="{Binding SelectedDropZones}" Grid.Column="1" AllowDrop="True" DisplayMemberPath="Id">
            <telerik:RadListBox.DragDropBehavior>
                <telerik:ListBoxDragDropBehavior />
            </telerik:RadListBox.DragDropBehavior>
        </telerik:RadListBox>
    </Grid>

    public class MainViewModel :ViewModelBase
    {
    public MainViewModel()
    {
    ObservableCollection<Friend> list = new ObservableCollection<Friend>();
    list.Add(new Friend() { Id = 1, Name = "Andy" });
    list.Add(new Friend() { Id = 2, Name = "Josh" });
    list.Add(new Friend() { Id = 3, Name = "Smith" });
    list.Add(new Friend() { Id = 4, Name = "Andrew" });
    AvailableDropZones = list;
    }

    ObservableCollection<Friend> availeble;
    public ObservableCollection<Friend> AvailableDropZones
    {
    get
    {
    return availeble;
    }
    set
    {
    if (availeble != value)
    {
    availeble = value;
    OnPropertyChanged("AvailableDropZones");
    }
    }
    }

    ObservableCollection<Friend> selected;
    public ObservableCollection<Friend> SelectedDropZones
    {
    get
    {
    return selected;
    }
    set
    {
    if (selected != value)
    {
    selected = value;
    OnPropertyChanged("SelectedDropZones");
    }
    }
    }

    }

    public class Friend
    {
    public int Id { get; set; }
    public string Name { get; set; }
    }
  2. Andy
    Andy avatar
    13 posts
    Member since:
    Apr 2014

    Posted 18 Jun 2014 in reply to Andy Link to this post

    Sorry I got the problem. I was not instantiating the SelectedDropZones in the view model.
    SelectedDropZones = new ObservableCollection<Friend     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Kalin
    Admin
    Kalin avatar
    1207 posts

    Posted 19 Jun 2014 Link to this post

    Hi Andy,

    We are glad you have managed to resolve the problem. If you have any other issues or concerns, please do not hesitate to contact us.

    Regards,
    Kalin
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
Back to Top