protected override void OnDrop(DragEventArgs e) { base.OnDrop(e); int?type = (int)(e.Data.GetData("ObjectType")); if (type != null) { Grid grid = new Grid() { Background = Brushes.Azure, Width = 65, Height = 65 }; TextObject ob = new TextObject() { Width = 65, Height = 65 }; ob.Content = grid; Console.WriteLine("Elemento Primario:" + LogicalTreeHelper.GetChildren(ob)); Point position = e.GetPosition(this); CanvasWorkspace.SetLeft(ob, Math.Max(0, position.X - ob.Width / 2)); CanvasWorkspace.SetTop(ob, Math.Max(0, position.Y - ob.Height / 2)); this.Children.Add(ob); this.DeselectAll(); ob.IsSelected = true; } e.Handled = true; }
private void MoveThumb_DragStarted(object sender, DragStartedEventArgs e) { this.element = DataContext as BaseObject; if (this.element != null) { this.canvasWorkspace = VisualTreeHelper.GetParent(this.element) as CanvasWorkspace; } }
public RubberbandAdorner(CanvasWorkspace canvasWorkspace, Point? dragStartPoint) : base(canvasWorkspace) { this.canvasWorkspace = canvasWorkspace; this.startPoint = dragStartPoint; this.adornerCanvas = new Canvas(); this.adornerCanvas.Background = Brushes.Transparent; this.visuals = new VisualCollection(this); this.visuals.Add(this.adornerCanvas); this.rubberband = new Rectangle(); this.rubberband.Stroke = Brushes.Navy; this.rubberband.StrokeThickness = 1; this.rubberband.StrokeDashArray = new DoubleCollection(new double[] { 2 }); this.adornerCanvas.Children.Add(this.rubberband); }