/// <summary> /// Occurs whenever the draggableElement is changed /// </summary> /// <param name="d"></param> /// <param name="e"></param> private static void DraggableChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { DragCanvas Target = d as DragCanvas; Target.dragcontent.Children.Clear(); if (e.NewValue != null) { Target.Visibility = Visibility.Visible; Target.dragcontent.Children.Add(e.NewValue as UserControl); } else { Target.Visibility = Visibility.Hidden; } }
private void DragQuery(object sender, MouseEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed) { DragCanvas Target = sender as DragCanvas; Point CursorLocation = e.GetPosition(Target); Size n = Target.RenderSize; double OffsetX = CursorLocation.X - (double)MyDraggableElement.ActualWidth * MouseOffset.Width; double OffsetY = CursorLocation.Y - (double)MyDraggableElement.ActualHeight * MouseOffset.Height; Canvas.SetLeft(MyDraggableElement, OffsetX); Canvas.SetTop(MyDraggableElement, OffsetY); Drag(MyDraggableElement, e); } else { UserControl Data = MyDraggableElement; MyDraggableElement = null; DragStop(Data, e); } }
private void MyDragCanvas_DragQuery(object sender, MouseEventArgs e) { DragCanvas DragSender = sender as DragCanvas; UserControl DragElement = DragSender.MyDraggableElement; //Get The hitbox of the draggable Element Point DragLocation = DragElement.TranslatePoint(default(Point), this); Size DragSize = DragElement.RenderSize; Rect DragHitBox = new Rect(DragLocation, DragSize); var PF = playingField.GridContent; Point FieldLocation = PF.TranslatePoint(default(Point), this); Size FieldSize = PF.RenderSize; Rect FieldHitBox = new Rect(FieldLocation, FieldSize); //Check if there is a HitBoxOverLap bool hitboxOverlap = HitBoxOverlap(DragHitBox, FieldHitBox); //the Draggable Element is hovering over the FieldHitbox, if (hitboxOverlap) { playingField.FindSpace(DragElement); } playingField.debug.Content += $" \n touch? {hitboxOverlap}"; }