Dragging an element from one user control into another.
Back To: Silverlight Tutorials
Also see:
![]() Dynamically loading Silverlight controls into resizable draggable windows. |
Download Code: Silverlight3DragAndDropExample.zip
This is an an example of code that will be incorporated into http://SilverlightDesktop.net.
The example is based on an earlier drag and drop code sample that was based on an example created by Keith Mahoney. It also uses a FloatingWindow control created by Tim Heuer.
When you open the sample you see two movable windows (you grab the Title bar on the top of the window to drag it).

You can click the "Show Floatable Window" button to display a Window with a picture in it. When you click and drag on the lower right hand corner of the window you can resize the window. Scroll bars will appear when needed to scroll the content of the resized window.
Only the label "Hello World!" can be dragged and dropped in this example.

To enable this feature, the word "[draggable]" is added to the Tag property of the control. When an element with that Tag is detected, the element is removed from the Canvas it is currently on and placed on the root Canvas of the application while it is being dragged.
When the element is dropped a HitTest is performed to see if the mouse is currently in the bounds of a FloatableWindow control in the application. If it is in the bounds of the control, the element is removed from the root Canvas and placed onto the Canvas of the respective FloatableWindow control.

The label will remain in the window and move with that window when that window is moved.