void MainWindow_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e) { RectInfo rect = null; Panel parent; if (SelControl == null) { return; } if (SelControl.Parent == null) { return; } if (Math.Abs(e.GetPosition(this).X - PushPoint.X) <= 2 && Math.Abs(e.GetPosition(this).Y - PushPoint.Y) <= 2 && IsAddPanel == false) { return; } if (IsAddPanel == false) { return; } RemovePanel(); rect = Collision(rectInfo, new Rect(e.GetPosition(this).X, e.GetPosition(this).Y, SelControl.ActualWidth, SelControl.ActualHeight)); if (rect == null) { return; } parent = SelControl.Parent as Panel; if (parent != null) { parent.Children.Remove(SelControl); } switch (rect.Container.GetType().Name) { case "DesignerCanvas": rect.Container.Children.Add(SelControl); Canvas.SetLeft(SelControl, e.GetPosition(rect.Container).X - point.X); Canvas.SetTop(SelControl, e.GetPosition(rect.Container).Y - point.Y); break; case "Grid": if (rect.Row != -1 && rect.Column != -1) { Grid.SetRow(SelControl, rect.Row); Grid.SetColumn(SelControl, rect.Column); } SelControl.Height = double.NaN; SelControl.Width = double.NaN; rect.Container.Children.Add(SelControl); break; } SelControl.IsSelected = true; SelControl = null; }
void MainWindow_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { Rectangle rect = new Rectangle(); DependencyObject element = this.InputHitTest(e.GetPosition(this)) as DependencyObject; if (element == null || element == this) { element = null; return; } if (e.LeftButton == MouseButtonState.Pressed) { SelControl = Common.FindVisualParent <jg.Editor.Library.DesignerItem>(element); if (SelControl == null) { point = new Point(0, 0); return; } IsAddPanel = false; if (SelControl.Parent == null) { return; } rectInfo = new RectInfo(this as Panel, new Point(0, 0)); if (SelControl.Parent is Grid) { SelControl.Height = 100; SelControl.Width = 100; } point = new Point(SelControl.Width / 2, SelControl.Height / 2); PushPoint = e.GetPosition(this); } }