private bool HandleDragEnd(Func <IInputElement, Point> eventPointExtractor) { AnnotationGridVM agVM = DataContext as AnnotationGridVM; if (agVM != null) { if (agVM.DraggedItem != null) { Point localOffset = agVM.LocalDraggedItemOffset; Point curLocation = eventPointExtractor(ColumnsGrid); Point droppedLocation = new Point( curLocation.X - localOffset.X + agVM.DraggedItem.ActualWidth / 2, //X coord is the location of the centre of the dragged element curLocation.Y - localOffset.Y); //Y coord is a top of the dragged element if (isMouseCaptured) { //ReleaseMouseCapture(); System.Diagnostics.Trace.WriteLine("Mouse release"); isMouseCaptured = false; } int col = -1; var htResult = VisualTreeHelper.HitTest(ColumnsGrid, droppedLocation); if (htResult != null) { foreach (UIElement elem in ColumnsGrid.Children) { if (IsInVisualTree(htResult.VisualHit, elem)) { col = Grid.GetColumn(elem); } } } ElementDropped?.Invoke(this, new ElemDroppedEventArgs(agVM.DraggedItem, col, droppedLocation.Y)); agVM.DraggedItem = null; return(true); } } return(false); }
protected override void OnManipulationCompleted(ManipulationCompletedEventArgs e) { base.OnManipulationCompleted(e); ElementDropped?.Invoke(this, new DraggableElementEventArgs(this, DragParent.PointToScreen(e.ManipulationOrigin))); }