DragandDrop between 2 ListBoxes

1 posts, 0 answers
  1. Inq
    Inq avatar
    1 posts
    Member since:
    Apr 2012

    Posted 15 May 2012 Link to this post

    I have a question/problem with DragAndDrop and listBoxes.
    I have two collections:
       var coll1 = new ObservableCollection<User>() {new User() {Id = 1}, new User() {Id = 2}};
      var coll2 = new ObservableCollection<User>() { new User() { Id = 2 }, new User() { Id = 4 } };


    I can  copy some items from listbox1 to listbox2 via draganddrop, but when i want to drag from listbox1 to listbox2 item User(id=2) I put listbox2.AllowDrop= false, because i don't want that listbox2 contains two equal items User(id=2)

    So it works, but i want more ;) I want to show why it is impossible to drop item to listbox.

            private void OnDragInitialize(object sender, DragInitializeEventArgs e)
                e.AllowedEffects = DragDropEffects.Copy;
                var data = ((FrameworkElement)e.OriginalSource).DataContext;
                e.DragVisual = new DragVisual()
                    Content = data,
                    ContentTemplate = this.Resources["DragTemplate"] as DataTemplate
                DataObject dataObject = new DataObject();
                dataObject.SetData("DragData", data);
                dataObject.SetData("Text", data.ToString());
                e.Data = data;

    I want to show something like this link

    Thanks in advance!
Back to Top