private static void OnPositionChanged(object sender, PositionChangedEventArgs args) { var compoundVertexControl = args.Source as CompoundVertexControl; if (compoundVertexControl == null || compoundVertexControl._activePositionChangeReaction) { return; } compoundVertexControl._activePositionChangeReaction = true; //we are moving the compound vertex itself if (compoundVertexControl == args.OriginalSource) { //move the children with the same amount foreach (var childVertexControl in compoundVertexControl.Vertices) { GraphCanvas.SetX(childVertexControl, GraphCanvas.GetX(childVertexControl) + args.XChange); GraphCanvas.SetY(childVertexControl, GraphCanvas.GetY(childVertexControl) + args.YChange); } } else { //we are moving the parent or one of it's child var childVertexControl = args.OriginalSource as VertexControl; if (childVertexControl == null) { return; } if (compoundVertexControl.Vertices.Contains(childVertexControl)) { //update the position of all child vertices foreach (var cvc in compoundVertexControl.Vertices) { if (cvc == childVertexControl) { continue; } var childCenterPos = new Point(cvc.ActualWidth / 2, cvc.ActualHeight / 2); var translatedChildCenterPos = cvc.TranslatePoint(childCenterPos, cvc.RootCanvas); GraphCanvas.SetX(cvc, translatedChildCenterPos.X - cvc.RootCanvas.Translation.X); GraphCanvas.SetY(cvc, translatedChildCenterPos.Y - cvc.RootCanvas.Translation.Y); } } } compoundVertexControl._activePositionChangeReaction = false; }
public AnimationContext(GraphCanvas canvas) { GraphCanvas = canvas; }
/// <summary> /// Initializes a new instance of the <see cref="AnimationContext"/> class. /// </summary> /// <param name="canvas">Graph canvas.</param> public AnimationContext([NotNull] GraphCanvas canvas) { GraphCanvas = canvas ?? throw new ArgumentNullException(nameof(canvas)); }