#region 拖拽事件
Point mouseOffest;
protected void canvalRoot_MouseLeftButtonDown(object o, MouseButtonEventArgs e)
{
Canvas obj = o as Canvas;
obj.CaptureMouse();
mouseOffest = e.GetPosition(obj);
obj.MouseMove += new MouseEventHandler(canvalRoot_MouseMove);
obj.MouseLeftButtonUp += new MouseButtonEventHandler(obj_MouseLeftButtonUp);
}
protected void obj_MouseLeftButtonUp(object o, MouseButtonEventArgs e)
{
Canvas obj = o as Canvas;
obj.ReleaseMouseCapture();
Point pointEnd = e.GetPosition(this.Parent as Canvas);
Canvas.SetLeft(obj, pointEnd.X - mouseOffest.X);
Canvas.SetTop(obj, pointEnd.Y - mouseOffest.Y);
obj.MouseMove -= new MouseEventHandler(canvalRoot_MouseMove);
obj.MouseLeftButtonUp -= new MouseButtonEventHandler(obj_MouseLeftButtonUp);
}
protected void canvalRoot_MouseMove(object o, MouseEventArgs e)
{
Canvas obj = o as Canvas;
Point pointNow = e.GetPosition(this.Parent as Canvas);
Canvas.SetLeft(obj, pointNow.X - mouseOffest.X);
Canvas.SetTop(obj, pointNow.Y - mouseOffest.Y);
}
#endregion
这只是基本的拖拽
SL3.0以上,可以实现拖放目标的事件
AllowDrop
DragEnter
DragLeave
DragOver
Drop
玩技术,要学会忍受寂寞--