Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable user to drag/drop WPF user controls anywhere on the page?

Now that I can make useful user controls in WPF (thanks to this stackoverflow answer) I want to be able to put numerous user controls on one page in two columns and enable the user to be able to move them around according to preference, dragging the ones they use the most to the top, etc.

Can anyone point me to code, tutorials, etc. which do this? I can imagine this has been made quite easy to do in WPF.

like image 203
Edward Tanguay Avatar asked Feb 04 '09 08:02

Edward Tanguay


People also ask

How do I enable drag and drop in WPF?

In the drag source event handler, call the DoDragDrop method to initiate the drag-and-drop operation. In the DoDragDrop call, specify the drag source, the data to be transferred, and the allowed effects. Identify the element that will be a drop target. A drop target can be UIElement or a ContentElement.

What is UserControl WPF?

User controls, in WPF represented by the UserControl class, is the concept of grouping markup and code into a reusable container, so that the same interface, with the same functionality, can be used in several different places and even across several applications.

How do I add user control to XAML?

Using a user control in XAML is pretty simple. I use a WPF Application to test the control. Create a WPF application project and copy the control code files to your project. After that, you need to add namespace of the library in which the user control is defined.


2 Answers

Here is a blog post to get you started on drag drop functionality in WPF.

Have Fun.

like image 146
Blounty Avatar answered Oct 12 '22 23:10

Blounty


There's also How can I drag and drop items between data bound ItemsControls? by Bea Stollnitz.

The article talks about a reusable set of adorners that enable drag-n-drop between controls.

It's somewhat advanced, but very useful.

like image 30
Cameron MacFarland Avatar answered Oct 13 '22 00:10

Cameron MacFarland