public RubberbandAdorner(DesignerCanvas designerCanvas, Point?dragStartPoint) : base(designerCanvas) { this.designerCanvas = designerCanvas; 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); }
public override void OnApplyTemplate() { base.OnApplyTemplate(); if (this.ScrollViewer == null) { return; } this.designerCanvas = this.ScrollViewer.Content as DesignerCanvas; if (this.designerCanvas == null) { throw new Exception("DesignerCanvas must not be null!"); } this.zoomThumb = Template.FindName("PART_ZoomThumb", this) as Thumb; if (this.zoomThumb == null) { throw new Exception("PART_ZoomThumb template is missing!"); } this.zoomCanvas = Template.FindName("PART_ZoomCanvas", this) as Canvas; if (this.zoomCanvas == null) { throw new Exception("PART_ZoomCanvas template is missing!"); } this.zoomSlider = Template.FindName("PART_ZoomSlider", this) as Slider; if (this.zoomSlider == null) { throw new Exception("PART_ZoomSlider template is missing!"); } this.designerCanvas.LayoutUpdated += new EventHandler(this.DesignerCanvas_LayoutUpdated); this.zoomThumb.DragDelta += new DragDeltaEventHandler(this.Thumb_DragDelta); this.zoomSlider.ValueChanged += new RoutedPropertyChangedEventHandler <double>(this.ZoomSlider_ValueChanged); this.scaleTransform = new ScaleTransform(); this.designerCanvas.LayoutTransform = this.scaleTransform; }
protected override void OnPreviewMouseDown(MouseButtonEventArgs e) { base.OnPreviewMouseDown(e); DesignerCanvas designer = VisualTreeHelper.GetParent(this) as DesignerCanvas; if (designer != null) { if ((Keyboard.Modifiers & (ModifierKeys.Shift | ModifierKeys.Control)) != ModifierKeys.None) { this.IsSelected = !this.IsSelected; } else { if (!this.IsSelected) { designer.DeselectAll(); this.IsSelected = true; } } } e.Handled = false; }
protected override void OnDrop(DragEventArgs e) { base.OnDrop(e); string xamlString = e.Data.GetData("DESIGNER_ITEM") as string; if (!String.IsNullOrEmpty(xamlString)) { DesignerItem newItem = null; FrameworkElement content = XamlReader.Load(XmlReader.Create(new StringReader(xamlString))) as FrameworkElement; if (content != null) { newItem = new DesignerItem(); newItem.Content = content; Point position = e.GetPosition(this); if (content.MinHeight != 0 && content.MinWidth != 0) { newItem.Width = content.MinWidth * 2;; newItem.Height = content.MinHeight * 2; } else { newItem.Width = 65; newItem.Height = 65; } DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X - newItem.Width / 2)); DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y - newItem.Height / 2)); this.Children.Add(newItem); this.DeselectAll(); newItem.IsSelected = true; } e.Handled = true; } }