static void DropTarget_PreviewDragOver(object sender, DragEventArgs e) { DropInfo dropInfo = new DropInfo(sender, e, m_DragInfo, m_Format.Name); IDropTarget dropHandler = GetDropHandler((UIElement)sender); if (dropHandler != null) { dropHandler.DragOver(dropInfo); } else { DefaultDropHandler.DragOver(dropInfo); } // Update the drag adorner. if (dropInfo.Effects != DragDropEffects.None) { if (DragAdorner == null && m_DragInfo != null) { CreateDragAdorner(); } if (DragAdorner != null) { DragAdorner.MousePosition = e.GetPosition(DragAdorner.AdornedElement); DragAdorner.InvalidateVisual(); } } else { DragAdorner = null; } // If the target is an ItemsControl then update the drop target adorner. if (sender is ItemsControl) { UIElement adornedElement = ((ItemsControl)sender).GetVisualDescendent <ItemsPresenter>(); if (dropInfo.DropTargetAdorner == null) { DropTargetAdorner = null; } else if (!dropInfo.DropTargetAdorner.IsInstanceOfType(DropTargetAdorner)) { DropTargetAdorner = DropTargetAdorner.Create(dropInfo.DropTargetAdorner, adornedElement); } if (DropTargetAdorner != null) { DropTargetAdorner.DropInfo = dropInfo; DropTargetAdorner.InvalidateVisual(); } } e.Effects = dropInfo.Effects; e.Handled = true; Scroll((DependencyObject)sender, e); }
private static void DropTarget_PreviewDragOver(object sender, DragEventArgs e) { var elementPosition = e.GetPosition((IInputElement)sender); if (HitTestUtilities.HitTest4Type <ScrollBar>(sender, elementPosition) || HitTestUtilities.HitTest4GridViewColumnHeader(sender, elementPosition) || HitTestUtilities.HitTest4DataGridTypesOnDragOver(sender, elementPosition)) { e.Effects = DragDropEffects.None; e.Handled = true; return; } var dropInfo = new DropInfo(sender, e, m_DragInfo); var dropHandler = TryGetDropHandler(dropInfo, sender as UIElement); var itemsControl = dropInfo.VisualTarget; dropHandler.DragOver(dropInfo); if (DragAdorner == null && m_DragInfo != null) { CreateDragAdorner(dropInfo); } if (DragAdorner != null) { var tempAdornerPos = e.GetPosition(DragAdorner.AdornedElement); if (tempAdornerPos.X >= 0 && tempAdornerPos.Y >= 0) { _adornerPos = tempAdornerPos; } // Fixed the flickering adorner - Size changes to zero 'randomly'...? if (DragAdorner.RenderSize.Width > 0 && DragAdorner.RenderSize.Height > 0) { _adornerSize = DragAdorner.RenderSize; } if (m_DragInfo != null) { // move the adorner var offsetX = _adornerSize.Width * -GetDragMouseAnchorPoint(m_DragInfo.VisualSource).X; var offsetY = _adornerSize.Height * -GetDragMouseAnchorPoint(m_DragInfo.VisualSource).Y; _adornerPos.Offset(offsetX, offsetY); var maxAdornerPosX = DragAdorner.AdornedElement.RenderSize.Width; var adornerPosRightX = (_adornerPos.X + _adornerSize.Width); if (adornerPosRightX > maxAdornerPosX) { _adornerPos.Offset(-adornerPosRightX + maxAdornerPosX, 0); } if (_adornerPos.Y < 0) { _adornerPos.Y = 0; } } DragAdorner.MousePosition = _adornerPos; DragAdorner.InvalidateVisual(); } // If the target is an ItemsControl then update the drop target adorner. if (itemsControl != null) { // Display the adorner in the control's ItemsPresenter. If there is no // ItemsPresenter provided by the style, try getting hold of a // ScrollContentPresenter and using that. var adornedElement = itemsControl is TabControl ? itemsControl.GetVisualDescendent <TabPanel>() : (itemsControl.GetVisualDescendent <ItemsPresenter>() ?? itemsControl.GetVisualDescendent <ScrollContentPresenter>() as UIElement ?? itemsControl); if (adornedElement != null) { if (dropInfo.DropTargetAdorner == null) { DropTargetAdorner = null; } else if (!dropInfo.DropTargetAdorner.IsInstanceOfType(DropTargetAdorner)) { DropTargetAdorner = DropTargetAdorner.Create(dropInfo.DropTargetAdorner, adornedElement); } if (DropTargetAdorner != null) { DropTargetAdorner.DropInfo = dropInfo; DropTargetAdorner.InvalidateVisual(); } } } // Set the drag effect adorner if there is one if (m_DragInfo != null && (EffectAdorner == null || EffectAdorner.Effects != dropInfo.Effects)) { CreateEffectAdorner(dropInfo); } if (EffectAdorner != null) { var adornerPos = e.GetPosition(EffectAdorner.AdornedElement); adornerPos.Offset(20, 20); EffectAdorner.MousePosition = adornerPos; EffectAdorner.InvalidateVisual(); } e.Effects = dropInfo.Effects; e.Handled = !dropInfo.NotHandled; if (!dropInfo.IsSameDragDropContextAsSource) { e.Effects = DragDropEffects.None; } Scroll(dropInfo.VisualTarget, e); }
private static void DropTargetOnDragOver(object sender, DragEventArgs e, EventType eventType) { var elementPosition = e.GetPosition((IInputElement)sender); var dragInfo = m_DragInfo; var dropInfo = new DropInfo(sender, e, dragInfo, eventType); var dropHandler = TryGetDropHandler(dropInfo, sender as UIElement); var itemsControl = dropInfo.VisualTarget; dropHandler.DragOver(dropInfo); if (DragAdorner == null && dragInfo != null) { CreateDragAdorner(dropInfo); } DragAdorner?.Move(e.GetPosition(DragAdorner.AdornedElement), dragInfo != null ? GetDragMouseAnchorPoint(dragInfo.VisualSource) : default(Point), ref _adornerMousePosition, ref _adornerSize); Scroll(dropInfo, e); if (HitTestUtilities.HitTest4Type <ScrollBar>(sender, elementPosition) || HitTestUtilities.HitTest4GridViewColumnHeader(sender, elementPosition) || HitTestUtilities.HitTest4DataGridTypesOnDragOver(sender, elementPosition)) { e.Effects = DragDropEffects.None; e.Handled = true; return; } // If the target is an ItemsControl then update the drop target adorner. if (itemsControl != null) { // Display the adorner in the control's ItemsPresenter. If there is no // ItemsPresenter provided by the style, try getting hold of a // ScrollContentPresenter and using that. UIElement adornedElement = null; if (itemsControl is TabControl) { adornedElement = itemsControl.GetVisualDescendent <TabPanel>(); } else if (itemsControl is DataGrid || (itemsControl as ListView)?.View is GridView) { adornedElement = itemsControl.GetVisualDescendent <ScrollContentPresenter>() as UIElement ?? itemsControl.GetVisualDescendent <ItemsPresenter>() as UIElement ?? itemsControl; } else { adornedElement = itemsControl.GetVisualDescendent <ItemsPresenter>() as UIElement ?? itemsControl.GetVisualDescendent <ScrollContentPresenter>() as UIElement ?? itemsControl; } if (adornedElement != null) { if (dropInfo.DropTargetAdorner == null) { DropTargetAdorner = null; } else if (!dropInfo.DropTargetAdorner.IsInstanceOfType(DropTargetAdorner)) { DropTargetAdorner = DropTargetAdorner.Create(dropInfo.DropTargetAdorner, adornedElement, dropInfo); } var adorner = DropTargetAdorner; if (adorner != null) { var adornerBrush = GetDropTargetAdornerBrush(dropInfo.VisualTarget); if (adornerBrush != null) { adorner.Pen.SetCurrentValue(Pen.BrushProperty, adornerBrush); } adorner.DropInfo = dropInfo; adorner.InvalidateVisual(); } } } // Set the drag effect adorner if there is one if (dragInfo != null && (EffectAdorner == null || EffectAdorner.Effects != dropInfo.Effects)) { CreateEffectAdorner(dropInfo); } EffectAdorner?.Move(e.GetPosition(EffectAdorner.AdornedElement), default(Point), ref _effectAdornerMousePosition, ref _effectAdornerSize); e.Effects = dropInfo.Effects; e.Handled = !dropInfo.NotHandled; if (!dropInfo.IsSameDragDropContextAsSource) { e.Effects = DragDropEffects.None; } }
static void DropTarget_PreviewDrop(object sender, DragEventArgs e) { DropInfo dropInfo = new DropInfo(sender, e, m_DragInfo, m_Format.Name); IDropTarget dropHandler = GetDropHandler((UIElement)sender); DragAdorner = null; DropTargetAdorner = null; if (dropHandler != null) { dropHandler.Drop(dropInfo); } else { DefaultDropHandler.Drop(dropInfo); } e.Handled = true; }
static void DropTarget_PreviewDragOver(object sender, DragEventArgs e) { DropInfo dropInfo = new DropInfo(sender, e, m_DragInfo, m_Format.Name); IDropTarget dropHandler = GetDropHandler((UIElement)sender); if (dropHandler != null) { dropHandler.DragOver(dropInfo); } else { DefaultDropHandler.DragOver(dropInfo); } // Update the drag adorner. if (dropInfo.Effects != DragDropEffects.None) { if (DragAdorner == null && m_DragInfo != null) { CreateDragAdorner(); } if (DragAdorner != null) { DragAdorner.MousePosition = e.GetPosition(DragAdorner.AdornedElement); DragAdorner.InvalidateVisual(); } } else { DragAdorner = null; } // If the target is an ItemsControl then update the drop target adorner. if (sender is ItemsControl) { UIElement adornedElement = ((ItemsControl)sender).GetVisualDescendent<ItemsPresenter>(); if (dropInfo.DropTargetAdorner == null) { DropTargetAdorner = null; } else if (!dropInfo.DropTargetAdorner.IsInstanceOfType(DropTargetAdorner)) { DropTargetAdorner = DropTargetAdorner.Create(dropInfo.DropTargetAdorner, adornedElement); } if (DropTargetAdorner != null) { DropTargetAdorner.DropInfo = dropInfo; DropTargetAdorner.InvalidateVisual(); } } e.Effects = dropInfo.Effects; e.Handled = true; Scroll((DependencyObject)sender, e); }
static void DropTarget_PreviewDragLeave(object sender, DragEventArgs e) { DragAdorner = null; DropTargetAdorner = null; }
private static void DropTarget_PreviewDrop(object sender, DragEventArgs e) { var dropInfo = new DropInfo(sender, e, m_DragInfo); var dropHandler = GetDropHandler((UIElement)sender) ?? DefaultDropHandler; var dragHandler = GetDragHandler((UIElement)sender) ?? DefaultDragHandler; DragAdorner = null; DropTargetAdorner = null; dropHandler.Drop(dropInfo); dragHandler.Dropped(dropInfo); e.Handled = true; }
private static void DropTarget_PreviewDragOver(object sender, DragEventArgs e) { var dropInfo = new DropInfo(sender, e, m_DragInfo); var dropHandler = GetDropHandler((UIElement)sender); var itemsControl = sender as ItemsControl; if (dropHandler != null) { dropHandler.DragOver(dropInfo); } else { DefaultDropHandler.DragOver(dropInfo); } // Update the drag adorner. if (dropInfo.Effects != DragDropEffects.None) { if (DragAdorner == null && m_DragInfo != null) { CreateDragAdorner(); } if (DragAdorner != null) { DragAdorner.MousePosition = e.GetPosition(DragAdorner.AdornedElement); DragAdorner.InvalidateVisual(); } } else { DragAdorner = null; } // If the target is an ItemsControl then update the drop target adorner. if (itemsControl != null) { // Display the adorner in the control's ItemsPresenter. If there is no // ItemsPresenter provided by the style, try getting hold of a // ScrollContentPresenter and using that. var adornedElement = (UIElement)itemsControl.GetVisualDescendent<ItemsPresenter>() ?? (UIElement)itemsControl.GetVisualDescendent<ScrollContentPresenter>(); if (adornedElement != null) { if (dropInfo.DropTargetAdorner == null) { DropTargetAdorner = null; } else if (!dropInfo.DropTargetAdorner.IsInstanceOfType(DropTargetAdorner)) { DropTargetAdorner = DropTargetAdorner.Create(dropInfo.DropTargetAdorner, adornedElement); } if (DropTargetAdorner != null) { DropTargetAdorner.DropInfo = dropInfo; DropTargetAdorner.InvalidateVisual(); } } } e.Effects = dropInfo.Effects; e.Handled = true; Scroll((DependencyObject)sender, e); }
static void DropTarget_PreviewDragLeave(object sender, DragEventArgs e) { IDropTarget dropHandler = GetDropHandler((UIElement)sender); DropInfo dropInfo = new DropInfo(sender, e, m_DragInfo, m_Format.Name); if (dropHandler != null) { dropHandler.DragOut(dropInfo); } DragAdorner = null; DropTargetAdorner = null; }
static void DropTarget_PreviewDragOver(object sender, DragEventArgs e) { DropInfo dropInfo = new DropInfo(sender, e, m_DragInfo); IDropTarget dropHandler = GetDropHandler((UIElement)sender); double adornerOpacity = GetAdornerOpacity((UIElement)sender); ItemsControl itemsControl = sender as ItemsControl; if (dropHandler != null) { dropHandler.DragOver(dropInfo); } else { DefaultDropHandler.DragOver(dropInfo); } // Update the drag adorner. //if (dropInfo.Effects != DragDropEffects.None) //{ // if (DragAdorner == null && m_DragInfo != null) // { // CreateDragAdorner(); // } // if (DragAdorner != null) // { // DragAdorner.MousePosition = e.GetPosition(DragAdorner.AdornedElement); // DragAdorner.InvalidateVisual(); // } //} //else //{ // DragAdorner = null; //} if (DragAdorner == null && m_DragInfo != null) { CreateDragAdorner(adornerOpacity); } if (DragAdorner != null) { DragAdorner.MousePosition = e.GetPosition(DragAdorner.AdornedElement); DragAdorner.InvalidateVisual(); } // If the target is an ItemsControl then update the drop target adorner. if (itemsControl != null) { // Display the adorner in the control's ItemsPresenter. If there is no // ItemsPresenter provided by the style, try getting hold of a // ScrollContentPresenter and using that. UIElement adornedElement = (UIElement)itemsControl.GetVisualDescendent <ItemsPresenter>() ?? (UIElement)itemsControl.GetVisualDescendent <ScrollContentPresenter>(); if (adornedElement != null) { if (dropInfo.DropTargetAdorner == null) { DropTargetAdorner = null; } else if (!dropInfo.DropTargetAdorner.IsInstanceOfType(DropTargetAdorner)) { DropTargetAdorner = DropTargetAdorner.Create(dropInfo.DropTargetAdorner, adornedElement); } if (DropTargetAdorner != null) { DropTargetAdorner.DropInfo = dropInfo; DropTargetAdorner.InvalidateVisual(); } } } e.Effects = dropInfo.Effects; e.Handled = true; Scroll((DependencyObject)sender, e); }