/// <summary> /// Initializes dragging of a line segment. /// </summary> /// <seealso cref="AutoPosModeOnly"/> /// <param name="e">The <see cref="T:System.Windows.Input.MouseButtonEventArgs"/> that contains the event data. This event data reports details about the mouse button that was pressed and the handled state.</param> protected override void OnMouseDown(MouseButtonEventArgs e) { if (e.ChangedButton == MouseButton.Left && !AutoPosModeOnly) { segmentDragging = true; dragLast = e.GetPosition(XCaseCanvas); int i = JunctionGeometryHelper.FindHitSegmentIndex(dragLast, Points); affectedPoints = new JunctionPoint[] { Points[i], Points[i + 1] }; startPositions = new Dictionary <DragThumb, rPoint>(); if (affectedPoints[0].Movable) { startPositions[affectedPoints[0]] = new rPoint(affectedPoints[0].Position) { tag = affectedPoints[0].Placement } } ; if (affectedPoints[1].Movable) { startPositions[affectedPoints[1]] = new rPoint(affectedPoints[1].Position) { tag = affectedPoints[1].Placement } } ; this.CaptureMouse(); } base.OnMouseDown(e); }
void viewHelperPointsCollection_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (e is ObservablePointCollection.PointCollectionChangedEventArgs && ((ObservablePointCollection.PointCollectionChangedEventArgs)e).PointPositionsMovedOnly) { for (int i = 0; i < viewHelperPointsCollection.Count; i++) { Point point = viewHelperPointsCollection[i]; Points[i].X = point.X; Points[i].Y = point.Y; } } else { switch (e.Action) { case NotifyCollectionChangedAction.Add: if (e.NewItems.Count != 1) { throw new ArgumentOutOfRangeException("e", "Only one added point expected."); } BreakLine(viewHelperPointsCollection[e.NewStartingIndex], e.NewStartingIndex); break; case NotifyCollectionChangedAction.Remove: if (e.OldItems.Count != 1) { throw new ArgumentOutOfRangeException("e", "Only one removed point expected."); } StraightenLine(e.OldStartingIndex); break; case NotifyCollectionChangedAction.Replace: if (e.NewItems.Count != 1) { throw new ArgumentOutOfRangeException("e", "Only one replaced point expected."); } rPoint newPoint = (rPoint)e.NewItems[0]; if (newPoint.tag is EPlacementKind) { Points[e.NewStartingIndex].Placement = (EPlacementKind)newPoint.tag; } viewHelperPointsCollection[e.NewStartingIndex].Set(newPoint); break; case NotifyCollectionChangedAction.Reset: break; default: throw new ArgumentOutOfRangeException("e", "Unknown action."); } } }