//拖动的区域
private FrameworkElement _dragScope;
//用于显示鼠标跟随效果的装饰器
private DragAdorner _adorner;
// 用于呈现DragAdorner的图画
private AdornerLayer _layer;
private void TextBlock_PreviewMouseMove_1(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
TextBlock t = (sender as TextBlock);
int id = (int)t.Tag;
task = findTask(id);
startMove(e, (t));
}
}
private void startMove(MouseEventArgs e, TextBlock t)
{
try
{
this._dragScope = Application.Current.MainWindow.Content as FrameworkElement;
this._dragScope.AllowDrop = true;
DragEventHandler draghandler = new DragEventHandler(DragScope_PreviewDragOver);
this._dragScope.PreviewDragOver += draghandler;
this._adorner = new DragAdorner(this._dragScope, (UIElement)t, 0.5);
this._layer = AdornerLayer.GetAdornerLayer(this._dragScope as Visual);
this._layer.Add(this._adorner);
DataObject data = new DataObject(typeof(Task), task);
DragDrop.DoDragDrop(t, data, DragDropEffects.Move);
AdornerLayer.GetAdornerLayer(this._dragScope).Remove(this._adorner);
this._adorner = null;
this._dragScope.PreviewDragOver -= draghandler;
}
catch (Exception ex)
{
Log.writeLog(ex.Message);
}
}
private void DragScope_PreviewDragOver(object sender, DragEventArgs args)
{
if (this._adorner != null)
{
this._adorner.LeftOffset = args.GetPosition(this._dragScope).X;
this._adorner.TopOffset = args.GetPosition(this._dragScope).Y;
}
}
4 个解决方案
#1
在window情况下测试正常
#2
同问。我也遇到了这个问题...
#3
同问。我也遇到了这个问题...
#4
LZ最后怎么解决的?可分享下嘛?
#1
在window情况下测试正常
#2
同问。我也遇到了这个问题...
#3
同问。我也遇到了这个问题...
#4
LZ最后怎么解决的?可分享下嘛?