Controls drag from the toolbox to the artboard let me think of the Tookit Dragdroptarget control, Toolbox say with a ListBox or TreeView, the artboard do not know how to do, so decided to do their own dragdrop.
On the left is a ListBox, and the red on the right is canvas. Create a class library Dragdroplibrary (this name doesn't know if it sounds good).
Click on the left side of the ListBox, and then move the mouse to the right side of the Red section, release the mouse control is placed in the loosened position, the idea is so simple.
Item on a TextBlock, we want to register the MouseLeftButtonDown event.
Show Sourceview sourceprint?01 using System.Windows;
Using System.Windows.Controls;
Using System.windows.input;
Using System.windows.media;
Using System.windows.media.imaging;
06
Modified namespace Dragdroplibrary
08 {
The public static class Dragdropmanage
10 {
One private static panel _root, _board;
//drop
delegate void Drop (Dragdropeventargs target);
private static Drop _ondrag;
private static Dragdropeventargs Eveargs;
16
17//Mouse Drag time following the effect
A private static image _mouseeffert;
19
///<summary>
21///Drag before calling
///</summary>
///<param name= "root" > Root panel (Children contains toolbox and artboards) </param>
///<param name= "board" > Artboard </param>
public static void register (panel root, panel board)
26 {
_root = root;
_board = Board;
If (_root is grid)
30 {
Grid.setcolumnspan (_mouseeffert, (_root as Grid). Columndefinitions.count+1);
Grid.setrowspan (_mouseeffert, _root as Grid). Rowdefinitions.count+1);
33}
34}
35
Static Dragdropmanage ()
37 {
_mouseeffert = new Image ();
39}
40
The public static void BeginDrag (object sender, MouseButtonEventArgs e, drop drop)
42 {
FrameworkElement target = sender as FrameworkElement;
WriteableBitmap bitmap = new WriteableBitmap (target, New TranslateTransform ());
_mouseeffert.source =bitmap;
_mouseeffert.height = Bitmap.pixelheight;
_mouseeffert.width = Bitmap.pixelwidth;
_root.children.add (_mouseeffert);
Point position = E.getposition (_root);
_mouseeffert.margin = new Thickness (position.x, position.y, 0, 0);
51
_mouseeffert.horizontalalignment = HorizontalAlignment.Left;
_mouseeffert.verticalalignment = Verticalalignment.top;
_mouseeffert.capturemouse ();
Eveargs = new Dragdropeventargs (target);
56
_ondrag = drop;
_root.mousemove + = Onrootmousemove;
_root.mouseleftbuttonup + = Onrootmouseleftbuttonup;
60}
61
The private static void clear ()
63 {
_root.mousemove-= Onrootmousemove;
_root.mouseleftbuttonup-= Onrootmouseleftbuttonup;
_root.children.remove (_mouseeffert);
_ondrag = null;
Eveargs = null;
69}
70
The private static void Onrootmouseleftbuttonup (object sender, MouseButtonEventArgs e)
72 {
Eveargs.position = E.getposition (_board);
_ondrag (Eveargs);
Clear ();
76}
77
Onrootmousemove private static void (object sender, MouseEventArgs e)
79 {
The point position = E.getposition (_root);
Bayi _mouseeffert.margin = new thickness (position.x, position.y, 0, 0);
82
The Point currentposition = E.getposition (_board);
if (currentposition.x > 0 && currentposition.x < _board.actualwidth
&& currentposition.y > 0 && currentposition.y < _board.actualheight)
86 {
Eveargs.accept = true;
88}
Or else
90 {
Eveargs.accept = false;
92}
93}
94}
95}
Show Sourceview sourceprint?01 using System;
Using System.Windows;
03
Namespace Dragdroplibrary
05 {
Dragdropeventargs:eventargs public class
07 {
accept bool {get; set;}
09
Ten public point position {get; internal set;}
11
FrameworkElement target {get; private set;}
13
Public Dragdropeventargs (FrameworkElement target)
15 {
target = target;
Position = new Point (0, 0);
18}
19}
20}