public void GenAllPathPosition(UIElementCollection children) { IEnumerable <PathPointNode> PathPointNodes = FindVisualChildren <PathPointNode>(this); foreach (FrameworkElement control in children) { if (control is Panel) { GenAllPathPosition((control as Panel).Children); } if (control is ListBox) { GenAllPathPosition(FindVisualChildren <PathPointNode>(control)); } if (control is PathPointNode) { PathPointNode node = control as PathPointNode; if (node.MyPath != null) { Point relativeLocation = node.TranslatePoint(new Point(5, 5), LayoutRoot); PathReDrawing(relativeLocation, node.MyPath.EndPathPosition, node.MyPath); node.MyPath.StartPosition = relativeLocation; } if (node.ComePath != null) { Point relativeLocation = node.TranslatePoint(new Point(5, 5), LayoutRoot); PathReDrawing(node.ComePath.StartPosition, relativeLocation, node.ComePath); node.ComePath.EndPathPosition = relativeLocation; } } } }
public void StartPath(RakunModuleViewModel Start, ref PathPointNode node) { //UIElement container = VisualTreeHelper.GetParent(control) as UIElement; Point relativeLocation = node.TranslatePoint(new Point(5, 5), LayoutRoot); node.MyPath.StartPosition = relativeLocation; node.MyPath.EndPathPosition = relativeLocation; node.MyPath.Path.Stroke = node.Foreground; isConnected = false; MovingPath = node; BeginnerPoint = Start; MovingPath.MyPath.Visibility = System.Windows.Visibility.Visible; if (node.NextPoint != null) { node.NextPoint.ComePath = null; if (MovingPath.NextPoint != null) { MovingPath.NextPoint.Disconnect(); } node.NextPoint = null; } }
private void GenAllPathPosition(System.Collections.IEnumerable enumerable) { System.Collections.IEnumerator e = enumerable.GetEnumerator(); while (e.MoveNext()) { if (e.Current is PathPointNode) { PathPointNode node = e.Current as PathPointNode; if (node.MyPath != null) { Point relativeLocation = node.TranslatePoint(new Point(5, 5), LayoutRoot); PathReDrawing(relativeLocation, node.MyPath.EndPathPosition, node.MyPath); node.MyPath.StartPosition = relativeLocation; } if (node.ComePath != null) { Point relativeLocation = node.TranslatePoint(new Point(5, 5), LayoutRoot); PathReDrawing(node.ComePath.StartPosition, relativeLocation, node.ComePath); node.ComePath.EndPathPosition = relativeLocation; } } } }
private void ObjectMouseMove(object sender, MouseEventArgs e) { /* * In this event, at first we check the mouse left button state. If it is pressed and * event sender object is similar with our moving object, we can move our control with * some effects. */ if (e.LeftButton == MouseButtonState.Pressed) { if (MovingObject == null) { if (MovingPath != null) { Point NowActualPostion = e.GetPosition((MovingPath.MyPath.Path as FrameworkElement).Parent as FrameworkElement); if (isConnected) { if (DestinationPoint != null) { Point relativeLocation = DestinationPoint.TranslatePoint(new Point(5, 5), LayoutRoot); if (relativeLocation.X < NowActualPostion.X + 15 && relativeLocation.X > NowActualPostion.X - 15 && relativeLocation.Y < NowActualPostion.Y + 15 && relativeLocation.Y > NowActualPostion.Y - 15) { //MyPathStartPosition PathReDrawing(MovingPath.MyPath.StartPosition, relativeLocation, MovingPath.MyPath); MovingPath.MyPath.EndPathPosition = relativeLocation; return; } } isConnected = false; DestinationPoint = null; } PathReDrawing(MovingPath.MyPath.StartPosition, NowActualPostion, MovingPath.MyPath); MovingPath.MyPath.EndPathPosition = NowActualPostion; } return; } // We start to moving objects with setting the lines positions. Path1.X1 = FirstArrowXPos; Path1.Y1 = FirstArrowYPos; Path1.X2 = e.GetPosition((MovingObject as FrameworkElement).Parent as FrameworkElement).X - FirstXPos; Path1.Y2 = e.GetPosition((MovingObject as FrameworkElement).Parent as FrameworkElement).Y - FirstYPos; Path2.X1 = Path1.X1 + (MovingObject as FrameworkElement).ActualWidth; Path2.Y1 = Path1.Y1; Path2.X2 = Path1.X2 + (MovingObject as FrameworkElement).ActualWidth; Path2.Y2 = Path1.Y2; Path3.X1 = Path1.X1; Path3.Y1 = Path1.Y1 + (MovingObject as FrameworkElement).ActualHeight; Path3.X2 = Path1.X2; Path3.Y2 = Path1.Y2 + (MovingObject as FrameworkElement).ActualHeight; Path4.X1 = Path1.X1 + (MovingObject as FrameworkElement).ActualWidth; Path4.Y1 = Path1.Y1 + (MovingObject as FrameworkElement).ActualHeight; Path4.X2 = Path1.X2 + (MovingObject as FrameworkElement).ActualWidth; Path4.Y2 = Path1.Y2 + (MovingObject as FrameworkElement).ActualHeight; FirstPosition.Width = (MovingObject as FrameworkElement).ActualWidth; FirstPosition.Height = (MovingObject as FrameworkElement).ActualHeight; FirstPosition.SetValue(Canvas.LeftProperty, FirstArrowXPos); FirstPosition.SetValue(Canvas.TopProperty, FirstArrowYPos); CurrentPosition.Width = (MovingObject as FrameworkElement).ActualWidth; CurrentPosition.Height = (MovingObject as FrameworkElement).ActualHeight; CurrentPosition.SetValue(Canvas.LeftProperty, Path1.X2); CurrentPosition.SetValue(Canvas.TopProperty, Path1.Y2); Path1.Visibility = System.Windows.Visibility.Visible; Path2.Visibility = System.Windows.Visibility.Visible; Path3.Visibility = System.Windows.Visibility.Visible; Path4.Visibility = System.Windows.Visibility.Visible; FirstPosition.Visibility = System.Windows.Visibility.Visible; CurrentPosition.Visibility = System.Windows.Visibility.Visible; /* * For changing the position of a control, we should use the SetValue method to setting * the Canvas.LeftProperty and Canvas.TopProperty dependencies. * * For calculating the currect position of the control, we should do : * Current position of the mouse cursor on the object parent - * Mouse position on the control at the start of moving - * position of the control's parent. */ (MovingObject as FrameworkElement).SetValue(Canvas.LeftProperty, e.GetPosition((MovingObject as FrameworkElement).Parent as FrameworkElement).X - FirstXPos); (MovingObject as FrameworkElement).SetValue(Canvas.TopProperty, e.GetPosition((MovingObject as FrameworkElement).Parent as FrameworkElement).Y - FirstYPos); if (MovingObject is ModuleView) { GenAllPathPosition((MovingObject as ModuleView).LayoutRoot.Children); } } }