/// <summary> /// This method updates the route polyline, especially by providing a new geometry. /// The DragAndDrop handling is corrected. /// </summary> /// <param name="points">Points defining the new geometry for the polyline.</param> /// <param name="toolTip">Tool tip of the hole polyline.</param> /// <param name="style">Display style of the polyline.</param> public void Update(IEnumerable <Point> points, string toolTip, ShapeStyle style) { if (route != null && !PointsExists()) { // remove drag and drop behavior InProcessDragDropBehavior.RemoveDragHandler(MapPolyline, Drag); InProcessDragDropBehavior.SetEnableDragDrop(MapPolyline, true); InProcessDragDropBehavior.RemoveDragHandler(AnimatedPolyline, Drag); InProcessDragDropBehavior.SetEnableDragDrop(AnimatedPolyline, true); } Dispose(); Points = points; ToolTip = toolTip; Color = style == null ? Colors.Black : style.Color; if (route == null || PointsExists()) { return; } // add drag and drop behavior InProcessDragDropBehavior.SetEnableDragDrop(MapPolyline, true); InProcessDragDropBehavior.AddDragHandler(MapPolyline, Drag); InProcessDragDropBehavior.SetEnableDragDrop(AnimatedPolyline, true); InProcessDragDropBehavior.AddDragHandler(AnimatedPolyline, Drag); }
/// <summary> /// Disposes the way point. /// </summary> public virtual void Dispose() { WayPointMouseRightButtonDown -= WayPoint_MouseRightButtonDown; InProcessDragDropBehavior.SetEnableDragDrop(this, false); InProcessDragDropBehavior.RemoveDragHandler(this, Drag); InProcessDragDropBehavior.RemoveDragMoveHandler(this, DragMove); layer.Shapes.Remove(this); }
/// <summary> /// Attaches (= forces) a Drag&Drop operation to the specified element. /// </summary> /// <param name="e">Element to Drag&Drop</param> /// <param name="dragPosition">Drag position</param> /// <param name="position">Current position. Defaults to dragPosition, if null.</param> /// <param name="fireInitialBegin">Forces a initial Drag event to be fired, if set to true.</param> public static void Attach(FrameworkElement e, Point dragPosition, Point?position = null, bool fireInitialBegin = false) { if (Mouse.LeftButton != MouseButtonState.Pressed) { throw new InvalidOperationException(); } var state = new InProcessDragDropBehavior { Target = e }; state.Attach(dragPosition, position, fireInitialBegin); }
/// <summary> /// Handles mouse left button down event /// </summary> /// <param name="sender">Event source</param> /// <param name="e">Event arguments</param> private static void PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { var state = new InProcessDragDropBehavior { Target = sender as FrameworkElement }; if (state.Target != null && state.Target.Parent != null) { state.Target.SetValue(DragDropState, state); state.PreviewMouseLeftButtonDown(e); } e.Handled = true; }
/// <summary> /// Creates the way point /// </summary> /// <param name="layer">Assigned route layer</param> /// <param name="p">Position of the way point (world coordinates)</param> /// <param name="style">Style of the way point</param> protected WayPoint(RouteLayer layer, Point p, ShapeStyle style) { this.layer = layer; Width = Height = style.Size; // set initial position and show polyline // do not use Point property to avoid LocationChanged event in initialization ShapeCanvas.SetLocation(this, p); // drag and drop handlers InProcessDragDropBehavior.AddDragHandler(this, Drag); InProcessDragDropBehavior.AddDragMoveHandler(this, DragMove); InProcessDragDropBehavior.SetEnableDragDrop(this, true); // handler for context menu MouseRightButtonDown += WayPoint_MouseRightButtonDown; }
/// <summary> /// Initiates a Drag&Drop operation on this way point. /// </summary> /// <param name="dragPosition"></param> /// <param name="position"></param> public void BeginDrag(Point dragPosition, Point?position = null) { InProcessDragDropBehavior.Attach(this, dragPosition, position); }
/// <summary> /// Initiates a Drag&Drop operation on this way point. /// </summary> /// <param name="dragPosition"></param> /// <param name="position"></param> public void BeginDrag(System.Windows.Point dragPosition, System.Windows.Point?position = null) { InProcessDragDropBehavior.Attach(this, dragPosition, position); }