Hi!
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 } };
listbox1.ItemSource=coll1;
listbox2.ItemSource=coll2;
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.SetText(data.ToString());
dataObject.SetData("DragData", data);
dataObject.SetData("Text", data.ToString());
e.Data = data;
}
I want to show something like this link
Thanks in advance!
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 } };
listbox1.ItemSource=coll1;
listbox2.ItemSource=coll2;
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.SetText(data.ToString());
dataObject.SetData("DragData", data);
dataObject.SetData("Text", data.ToString());
e.Data = data;
}
I want to show something like this link
Thanks in advance!