WPF ListBox Drag and Drop

1 Answer 45 Views
DragAndDrop ListBox
Dean
Top achievements
Rank 1
Dean asked on 27 Aug 2021, 10:11 AM

Hi,

I have a project where I need to be able to drag a ListBox Item to a different ListBox. If I dont populate the second Listbox with anything; then when I drop the item, it just disappears. When I have at least 1 Item in the second ListBox then I get "'Element already has a logical parent. It must be detached from the old parent before it is attached to a new one". I need to be able to do this as well as add a prefix to each added item eg: "A - FirstItem" and "B - SecondItem".

I tried using the Converter class too but it doesnt seem to work. It is important to note that I have tried this method using Binding as well as just dynamically adding objects to the Listbox. Nothing works. Attached is all the images from my sample project needed to diagnose my issue.

Please Help

Thank you,

Dean.

1 Answer, 1 is accepted

Sort by
0
Stenly
Telerik team
answered on 31 Aug 2021, 01:21 PM

Hello Dean,

The framework throws this exception because the item which is attempted to be added is already a child of another element. What I could suggest, in order to avoid this exception, is to set the ItemSource of the list boxes, instead of adding items to the Items collection.

That said, I have prepared a sample project, implementing the mentioned approach, as well as the xaml code from Capture.Png image file. 

Regards,
Stenly
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
DragAndDrop ListBox
Asked by
Dean
Top achievements
Rank 1
Answers by
Stenly
Telerik team
Share this question
or