private void AssociatedObject_DropCompleted(object sender, DropCompletedEventArgs e) { if (_dragVisual != null) { _dragVisual.Destroy(); _dragVisual = null; } }
private void AssociateObject_DragEnter(object sender, DragEventArgs e) { if (_dragVisual == null) { Panel source = sender as Panel; //FrameworkElement dragVisual = null; Point dragStart = DragManager.DragStartPosition; Control dragItem = GetDragItemControl(source, dragStart); Point itemPos = dragItem.TranslatePoint(new Point(), source); if (DragVisualTemplate == null) { DragVisualTemplate = GetDefaultDataTemplate(); } Point position = e.GetPosition(source); Point offset = new Point(dragStart.X - itemPos.X, dragStart.Y - itemPos.Y); Size size = new Size(dragItem.ActualWidth, dragItem.ActualHeight); IList data = DragDataManager.GetData(e.Data); _dragVisual = new DragVisual(data, source, DragVisualTemplate, offset, size); //if (dragItem.Parent is ItemsControl) //{ // ItemsControl parent = dragItem.Parent as ItemsControl; // DataTemplate template = parent.ItemTemplate; // if (template == null) // { // DragVisualTemplate = GetDefaultDataTemplate(); // } // else // { // DragVisualTemplate = template; // } // Point position = e.GetPosition(source); // Point offset = new Point(position.X - itemPos.X, position.Y - itemPos.Y); // Size size = new Size(dragItem.ActualWidth, dragItem.ActualHeight); // _dragVisual = new DragVisual(e.Data.GetData(DragDataManager.DataFormat) as IList, source, DragVisualTemplate, offset, size); //} //else //{ // dragVisual = CloneElement(dragItem); // Point position = e.GetPosition(source); // Point offset = new Point(position.X - itemPos.X, position.Y - itemPos.Y); // Size size = new Size(dragItem.ActualWidth, dragItem.ActualHeight); // _dragVisual = new DragVisual(e.Data.GetData(DragDataManager.DataFormat), source, offset, size, dragVisual); //} } }