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 virtual void OnDesignerCanvasChanged(DesignerCanvas oldDesignerCanvas, DesignerCanvas newDesignerCanvas) { if (newDesignerCanvas != null) { newDesignerCanvas.LayoutUpdated += new EventHandler(this.DesignerCanvas_LayoutUpdated); newDesignerCanvas.LayoutTransform = this.scaleTransform; } }
public RubberbandAdorner(DesignerCanvas designerCanvas, Point? dragStartPoint) : base(designerCanvas) { this.designerCanvas = designerCanvas; this.startPoint = dragStartPoint; rubberbandPen = new Pen(Brushes.LightSlateGray, 1); rubberbandPen.DashStyle = new DashStyle(new double[] { 2 }, 1); }
private void MoveThumb_DragStarted(object sender, DragStartedEventArgs e) { this.designerItem = DataContext as DesignerItem; if (this.designerItem != null) { this.designerCanvas = VisualTreeHelper.GetParent(this.designerItem) as DesignerCanvas; } }
public ConnectorAdorner(DesignerCanvas designer, Connector sourceConnector) : base(designer) { this.designerCanvas = designer; this.sourceConnector = sourceConnector; drawingPen = new Pen(Brushes.LightSlateGray, 1); drawingPen.LineJoin = PenLineJoin.Round; this.Cursor = Cursors.Cross; }
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: this.MyDesigner = ((DiagramDesigner.DesignerCanvas)(target)); return; } this._contentLoaded = true; }
internal ConnectorInfo GetInfo() { ConnectorInfo info = new ConnectorInfo(); info.DesignerItemLeft = DesignerCanvas.GetLeft(this.ParentDesignerItem); info.DesignerItemTop = DesignerCanvas.GetTop(this.ParentDesignerItem); info.DesignerItemSize = new Size(this.ParentDesignerItem.ActualWidth, this.ParentDesignerItem.ActualHeight); info.Orientation = this.Orientation; info.Position = this.Position; return(info); }
public DesignerItem AddDesignerItem(FrameworkElement item, Point position, Size?size, int layer = 0, bool insertInBackground = false, Guid?itemGuid = null) { DesignerItem newItem = new DesignerItem(); if (itemGuid != null) { newItem.ID = itemGuid.Value; } newItem.Content = item; newItem.Layer = layer; if (size.HasValue) { newItem.Width = size.Value.Width; newItem.Height = size.Value.Height; } DesignerCanvas.SetLeft(newItem, position.X); DesignerCanvas.SetTop(newItem, position.Y); //Canvas.SetZIndex(newItem, this.Children.Count); newItem.ZIndex = this.Children.Count; if (insertInBackground) { newItem.ZIndex = 0; this.Children.Insert(0, newItem); } else { this.Children.Add(newItem); } SetConnectorDecoratorTemplate(newItem); //update selection //this.SelectionService.SelectItem(newItem); //newItem.Focus(); raiseDesignerItemAdded(item, newItem); bool layerVisible = false; if (!visibleLayers.TryGetValue(layer, out layerVisible) || layerVisible) { item.Visibility = System.Windows.Visibility.Visible; } else { item.Visibility = System.Windows.Visibility.Hidden; } //updateVisibleDesigneritems(); return(newItem); }
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: this.SearchFrame = ((DiagramDesigner.SearchTextBox)(target)); return; case 2: this.SiderbarScrollViewer = ((System.Windows.Controls.ScrollViewer)(target)); return; case 3: this.SymbolStencilsScrollViewer = ((System.Windows.Controls.ScrollViewer)(target)); return; case 4: this.ConditionStencilsScrollViewer = ((System.Windows.Controls.ScrollViewer)(target)); return; case 5: this.ActionStencilsScrollViewer = ((System.Windows.Controls.ScrollViewer)(target)); return; case 6: this.TargetStencilsScrollViewer = ((System.Windows.Controls.ScrollViewer)(target)); return; case 7: this.TargetScrollViewer = ((System.Windows.Controls.ScrollViewer)(target)); return; case 8: this.TargetPanel = ((System.Windows.Controls.StackPanel)(target)); return; case 9: this.DesignerScrollViewer = ((System.Windows.Controls.ScrollViewer)(target)); return; case 10: this.MyDesignerCanvas = ((DiagramDesigner.DesignerCanvas)(target)); return; case 11: this.AiBarScrollViewer = ((System.Windows.Controls.ScrollViewer)(target)); return; case 12: this.AiBar = ((System.Windows.Controls.StackPanel)(target)); return; } this._contentLoaded = true; }
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) { base.OnMouseLeftButtonDown(e); DesignerCanvas canvas = GetDesignerCanvas(this); if (canvas != null) { // position relative to DesignerCanvas this.dragStartPoint = new Point?(e.GetPosition(canvas)); e.Handled = true; } }
private Connector GetConnector(Guid itemID, String connectorName, DesignerCanvas canvas) { DesignerItem designerItem = (from item in canvas.Children.OfType <DesignerItem>() where item.ID == itemID select item).FirstOrDefault(); Control connectorDecorator = designerItem.Template.FindName("PART_ConnectorDecorator", designerItem) as Control; connectorDecorator.ApplyTemplate(); return(connectorDecorator.Template.FindName(connectorName, connectorDecorator) as Connector); }
protected override void OnPreviewMouseDown(MouseButtonEventArgs e) { base.OnPreviewMouseDown(e); DesignerCanvas designer = VisualTreeHelper.GetParent(this) as DesignerCanvas; // update selection if (designer != null) { if ((Keyboard.Modifiers & (ModifierKeys.Shift | ModifierKeys.Control)) != ModifierKeys.None) { if (this.IsSelected) { designer.SelectionService.RemoveFromSelection(this); } else { designer.SelectionService.AddToSelection(this); } } else if (!this.IsSelected) { designer.SelectionService.SelectItem(this); //if (!string.IsNullOrEmpty(this.RealatedPorpertyCardName)) //{ this.RealatedPorpertyCardName = "PropertyGridCard"; PropertyGridControl card = designer.FindName(this.RealatedPorpertyCardName) as PropertyGridControl; if (card != null) { var count = VisualTreeHelper.GetChildrenCount(this); for (int i = 0; i <= count - 1; i++) { var child = VisualTreeHelper.GetChild(this, i); var length = VisualTreeHelper.GetChildrenCount(child); for (int j = 0; j < length; j++) { var aa = VisualTreeHelper.GetChild(child, j) as ContentPresenter; if (aa != null) { card.SelectedObject = aa.Content; } } } } } Focus(); } e.Handled = false; }
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: this.PropertyGrid = ((Xceed.Wpf.Toolkit.PropertyGrid.PropertyGrid)(target)); return; case 2: this.MyDesigner = ((DiagramDesigner.DesignerCanvas)(target)); return; } this._contentLoaded = true; }
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: this.wfhPropertyGrid = ((System.Windows.Forms.Integration.WindowsFormsHost)(target)); return; case 2: this.MyDesigner = ((DiagramDesigner.DesignerCanvas)(target)); return; } this._contentLoaded = true; }
protected override void OnDrop(DragEventArgs e) { base.OnDrop(e); DragObject dragObject = e.Data.GetData(typeof(DragObject)) as DragObject; if (dragObject != null && !String.IsNullOrEmpty(dragObject.Xaml)) { DesignerItem newItem = null; Object content = XamlReader.Load(XmlReader.Create(new StringReader(dragObject.Xaml))); if (content != null) { newItem = new DesignerItem(dragObject.Tag); newItem.Content = content; var temp = newItem as ContentControl; var abc = temp.Content as TextBox; Point position = e.GetPosition(this); if (dragObject.DesiredSize.HasValue) { Size desiredSize = dragObject.DesiredSize.Value; newItem.Width = desiredSize.Width; newItem.Height = desiredSize.Height; DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X - newItem.Width / 2)); DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y - newItem.Height / 2)); } else { DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X)); DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y)); } Canvas.SetZIndex(newItem, this.Children.Count); this.Children.Add(newItem); SetConnectorDecoratorTemplate(newItem); //update selection this.SelectionService.SelectItem(newItem); EnsureComponentUniqueName(newItem); newItem.Focus(); } e.Handled = true; } }
protected override void OnDrop(DragEventArgs e) { base.OnDrop(e); Console.WriteLine("Dropped"); DragObject dragObject = e.Data.GetData(typeof(DragObject)) as DragObject; if (dragObject != null && !String.IsNullOrEmpty(dragObject.Xaml)) { DesignerItem newItem = null; Object content = XamlReader.Load(XmlReader.Create(new StringReader(dragObject.Xaml))); if (content != null) { newItem = new DesignerItem(); newItem.Content = content; newItem.primaryField = (Window.GetWindow(this) as Window1).tbComponentName.Text; newItem.secondaryField = (Window.GetWindow(this) as Window1).tbComponentDesc.Text; Point position = e.GetPosition(this); if (dragObject.DesiredSize.HasValue) { Size desiredSize = dragObject.DesiredSize.Value; newItem.Width = desiredSize.Width; newItem.Height = desiredSize.Height; DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X - newItem.Width / 2)); DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y - newItem.Height / 2)); } else { DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X)); DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y)); } Canvas.SetZIndex(newItem, this.Children.Count); this.Children.Add(newItem); SetConnectorDecoratorTemplate(newItem); //update selection this.SelectionService.SelectItem(newItem); newItem.Focus(); } e.Handled = true; Console.WriteLine("handled creation"); } }
private void ShowAdorner() { // the ConnectionAdorner is created once for each Connection if (this.connectionAdorner == null) { DesignerCanvas designer = VisualTreeHelper.GetParent(this) as DesignerCanvas; AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(this); if (adornerLayer != null) { this.connectionAdorner = new ConnectionAdorner(designer, this); adornerLayer.Add(this.connectionAdorner); } } this.connectionAdorner.Visibility = Visibility.Visible; }
protected virtual void OnDesignerCanvasChanged(DesignerCanvas oldDesignerCanvas, DesignerCanvas newDesignerCanvas) { if (oldDesignerCanvas != null) { newDesignerCanvas.LayoutUpdated -= new EventHandler(this.DesignerCanvas_LayoutUpdated); newDesignerCanvas.MouseWheel -= new MouseWheelEventHandler(this.DesignerCanvas_MouseWheel); } if (newDesignerCanvas != null) { newDesignerCanvas.LayoutUpdated += new EventHandler(this.DesignerCanvas_LayoutUpdated); newDesignerCanvas.MouseWheel += new MouseWheelEventHandler(this.DesignerCanvas_MouseWheel); newDesignerCanvas.LayoutTransform = this.scaleTransform; } }
private void findParts() { if (eventsAdded) { this.designerCanvas.LayoutUpdated -= this.DesignerCanvas_LayoutUpdated; this.zoomThumb.DragDelta -= this.Thumb_DragDelta; this.zoomSlider.ValueChanged -= this.ZoomSlider_ValueChanged; eventsAdded = false; } if (this.ScrollViewer == null || !templateApplied) { 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 += this.DesignerCanvas_LayoutUpdated; this.zoomThumb.DragDelta += this.Thumb_DragDelta; this.zoomSlider.ValueChanged += this.ZoomSlider_ValueChanged; eventsAdded = true; this.scaleTransform = new ScaleTransform(); this.designerCanvas.LayoutTransform = this.scaleTransform; this.designerCanvas.ScaleChanged += designerCanvas_ScaleChanged; }
protected override void OnDrop(DragEventArgs e) { base.OnDrop(e); DragObject dragObject = e.Data.GetData(typeof(DragObject)) as DragObject; if (dragObject != null && !String.IsNullOrEmpty(dragObject.Xaml)) { DesignerItem newItem = null; Object content = XamlReader.Load(XmlReader.Create(new StringReader(dragObject.Xaml))); if (content != null) { itemCounter = this.Children.OfType <DesignerItem>().Where(x => x.Tag.ToString() == dragObject.Class).Count(); newItem = new DesignerItem(Guid.NewGuid(), dragObject.Class, ++itemCounter); newItem.Content = content; newItem.MouseDoubleClick += DesignerItem_MouseDoubleClick; Point position = e.GetPosition(this); if (dragObject.DesiredSize.HasValue) { Size desiredSize = dragObject.DesiredSize.Value; newItem.Width = desiredSize.Width; newItem.Height = desiredSize.Height; DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X - newItem.Width / 2)); DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y - newItem.Height / 2)); } else { DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X)); DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y)); } Canvas.SetZIndex(newItem, this.Children.Count); this.Children.Add(newItem); SetConnectorDecoratorTemplate(newItem); //update selection this.SelectionService.SelectItem(newItem); newItem.Focus(); } e.Handled = true; } }
protected void OnPropertyChanged(string name) { PropertyChangedEventHandler handler = PropertyChanged; if (handler != null) { handler(this, new PropertyChangedEventArgs(name)); //update name of the selected item, when name is changed in attribute panel Window mw = App.Current.MainWindow; DesignerCanvas designer = (DesignerCanvas)mw.FindName("RBPDesigner"); DesignerItem item = ((DesignerItem)designer.SelectionService.CurrentSelection[0]); item.dispName = this.Name; ((Operation)item.BoundLogicItem).Name = this.Name; } }
public ConnectionAdorner(DesignerCanvas designer, Connection connection) : base(designer) { this.designerCanvas = designer; adornerCanvas = new Canvas(); this.visualChildren = new VisualCollection(this); this.visualChildren.Add(adornerCanvas); this.connection = connection; this.connection.PropertyChanged += new PropertyChangedEventHandler(AnchorPositionChanged); InitializeDragThumbs(); drawingPen = new Pen(Brushes.LightSlateGray, 1); drawingPen.LineJoin = PenLineJoin.Round; }
protected override void OnDrop(DragEventArgs e) { base.OnDrop(e); DragObject dragObject = e.Data.GetData(typeof(DragObject)) as DragObject; if (dragObject != null && !String.IsNullOrEmpty(dragObject.Xaml)) { DesignerItem newItem = null; Object content = XamlReader.Load(XmlReader.Create(new StringReader(dragObject.Xaml))); if (content != null) { newItem = new DesignerItem(); newItem.Content = content; Point position = e.GetPosition(this); if (dragObject.DesiredSize.HasValue) { Size desiredSize = dragObject.DesiredSize.Value; newItem.Width = desiredSize.Width; newItem.Height = desiredSize.Height; DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X - newItem.Width / 2)); DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y - newItem.Height / 2)); } else { DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X)); DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y)); } this.Children.Add(newItem); //update selection foreach (ISelectable item in this.SelectedItems) { item.IsSelected = false; } SelectedItems.Clear(); newItem.IsSelected = true; this.SelectedItems.Add(newItem); } e.Handled = true; } }
protected override void OnDrop(DragEventArgs e) { base.OnDrop(e); if (!String.IsNullOrEmpty(name)) { node.comboData = ListData; DesignerItem newItem = node.addNode(name, nodeFileName); if (newItem.ItemType == "Target") { bool hasExist = false; for (int i = 0; i < targetPanel.Children.Count; ++i) { DesignerItem temp = targetPanel.Children[i] as DesignerItem; if (newItem.IDName.Equals(temp.IDName)) { hasExist = true; break; } } if (!hasExist) { this.targetPanel.Children.Add(newItem); int id = ListData.Count - 1; string value = id.ToString(); ListData.Add(new ComboData { Id = id, Value = value }); AddTriggerItem(newItem.ItemType, newItem); } } else { Point position = e.GetPosition(this); DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X)); DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y)); Canvas.SetZIndex(newItem, this.Children.Count); this.Children.Add(newItem); SetConnectorDecoratorTemplate(newItem); //update selection this.SelectionService.SelectItem(newItem); AddTriggerItem(newItem.ItemType, newItem); newItem.Focus(); } e.Handled = true; } }
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 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); }
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.Style = this.TryFindResource("DesignerItemStyle") as Style; 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; //} double unitwidth = this.ActualWidth / MyCols; double unitheight = this.ActualHeight / MyRows; newItem.Width = unitwidth; newItem.Height = unitheight; double left = Math.Floor(position.X / unitwidth) * unitwidth; double top = Math.Floor(position.Y / unitheight) * unitheight; DesignerCanvas.SetLeft(newItem, Math.Max(0, left /*position.X - newItem.Width / 2*/)); DesignerCanvas.SetTop(newItem, Math.Max(0, top /*position.Y - newItem.Height / 2*/)); this.Children.Add(newItem); this.DeselectAll(); newItem.IsSelected = true; } e.Handled = true; } }
public RubberbandAdorner(DesignerCanvas designerCanvas, Point?dragStartPoint) : base(designerCanvas) { this.designerCanvas = designerCanvas; this.startPoint = dragStartPoint; SolidColorBrush SelectWhenTouchBrush = new SolidColorBrush(Colors.ForestGreen); SelectWhenTouchBrush.Opacity = 0.7; SolidColorBrush SelectWhenContainsBrush = new SolidColorBrush(Colors.DodgerBlue); SelectWhenContainsBrush.Opacity = 0.7; SelectWhenTouchRubberbandPen = new Pen(SelectWhenTouchBrush, 1.5); SelectWhenContainsRubberbandPen = new Pen(SelectWhenContainsBrush, 1.5); //rubberbandPen.DashStyle = new DashStyle(new double[] { 2 }, 1); }
private void DesignerItem_Loaded(object sender, RoutedEventArgs e) { if (this.Template != null) { ContentPresenter contentPresenter = this.Template.FindName("PART_ContentPresenter", this) as ContentPresenter; MoveThumb thumb = this.Template.FindName("PART_MoveThumb", this) as MoveThumb; MenuItem menu_delete = this.Template.FindName("PART_Delete", this) as MenuItem; if (menu_delete != null) { //delete the DesignerItem menu_delete.Click += new RoutedEventHandler((x, y) => { DesignerCanvas designer = (DesignerCanvas)VisualTreeHelper.GetParent(this); if (designer != null) { designer.Children.Remove(this); } }); } if (contentPresenter != null && thumb != null) { UIElement contentVisual = VisualTreeHelper.GetChild(contentPresenter, 0) as UIElement; if (contentVisual != null) { ControlTemplate template = DesignerItem.GetMoveThumbTemplate(contentVisual) as ControlTemplate; if (template != null) { thumb.Template = template; } } } } }
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; // update selection if (designer != null) { if ((Keyboard.Modifiers & (ModifierKeys.Shift | ModifierKeys.Control)) != ModifierKeys.None) { if (this.IsSelected) { designer.SelectionService.RemoveFromSelection(this); designer.SelectionService.RaiseSelectionChanged(); } else { designer.SelectionService.AddToSelection(this); designer.SelectionService.RaiseSelectionChanged(); } } else if (!this.IsSelected) { var elm = Mouse.DirectlyOver; var connector = elm as Connector; var parent = elm as DependencyObject; while (parent != null && connector == null) { parent = VisualTreeHelper.GetParent(parent); connector = parent as Connector; } if (connector == null) { designer.SelectionService.SelectItem(this); } } Focus(); } e.Handled = false; }
protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); // if mouse button is not pressed we have no drag operation, ... if (e.LeftButton != MouseButtonState.Pressed) { this.dragStartPoint = null; } // but if mouse button is pressed and start point value is set we do have one if (this.dragStartPoint.HasValue) { if (this.IsSourceConnector && (!this.OnlyOneConnectionCanStart || !this.Connections.Any(x => Equals(x.Source, this)))) { // create connection adorner DesignerCanvas canvas = GetDesignerCanvas(this); if (canvas != null) { var connections = canvas.Children.OfType <Connection>(); foreach (var connection in connections) { connection.IsHitTestVisible = false; } AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(canvas); if (adornerLayer != null) { ConnectorAdorner adorner = new ConnectorAdorner(canvas, this); if (adorner != null) { adornerLayer.Add(adorner); e.Handled = true; } } } } } }
void Connection_Unloaded(object sender, RoutedEventArgs e) { // do some housekeeping when Connection is unloaded // remove event handler source.PropertyChanged -= new PropertyChangedEventHandler(OnConnectorPositionChanged); sink.PropertyChanged -= new PropertyChangedEventHandler(OnConnectorPositionChanged); // remove adorner if (this.connectionAdorner != null) { DesignerCanvas designer = VisualTreeHelper.GetParent(this) as DesignerCanvas; AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(designer); if (adornerLayer != null) { adornerLayer.Remove(this.connectionAdorner); this.connectionAdorner = null; } } }
protected override void OnMouseDoubleClick(MouseButtonEventArgs e) { base.OnMouseDoubleClick(e); DesignerCanvas designer = VisualTreeHelper.GetParent(this) as DesignerCanvas; if (designer != null) { double h = designer.ActualHeight / designer.MyRows; double w = designer.ActualWidth / designer.MyCols; double left = DesignerCanvas.GetLeft(this); double top = DesignerCanvas.GetTop(this); double newleft = System.Math.Floor(left / w) * w; double newtop = System.Math.Floor(top / h) * h; double newright = System.Math.Ceiling((left + this.ActualWidth) / w) * w; double newbottom = System.Math.Ceiling((top + this.ActualHeight) / h) * h; DesignerCanvas.SetLeft(this, newleft); DesignerCanvas.SetTop(this, newtop); this.Width = newright - newleft; this.Height = newbottom - newtop; } }
void Connection_Unloaded(object sender, RoutedEventArgs e) { // do some housekeeping when Connection is unloaded // remove event handler this.Source = null; this.Sink = null; // remove adorner if (this.connectionAdorner != null) { DesignerCanvas designer = VisualTreeHelper.GetParent(this) as DesignerCanvas; AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(this); if (adornerLayer != null) { adornerLayer.Remove(this.connectionAdorner); this.connectionAdorner = null; } } }
protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (e.RightButton == MouseButtonState.Pressed) { Point _actualMousePosition = Mouse.GetPosition(this); if (Point.Subtract(_copyOperationMousePosition, _actualMousePosition).Length > 10) { //copying should occur when dragged DesignerCanvas designer = VisualTreeHelper.GetParent(this) as DesignerCanvas; var selectedItems = from item in designer.SelectionService.CurrentSelection.OfType <DesignerItem>() select item; List <ElementVM> selectedElementsVM = new List <ElementVM>(); foreach (DesignerItem item in selectedItems) { if (item.DataContext is ElementVM elementVM) { selectedElementsVM.Add(elementVM); } } var selectedConnections = from connection in designer.SelectionService.CurrentSelection.OfType <Connection>() select connection; List <ConnectionVM> selectedConnectionsVM = new List <ConnectionVM>(); foreach (Connection connection in selectedConnections) { if (connection.DataContext is ConnectionVM connectionVM) { selectedConnectionsVM.Add(connectionVM); } } string returnedString = (designer.DataContext as MainVM).WriteElementsAndConnectionsToString(selectedElementsVM, selectedConnectionsVM); DragString dragString = new DragString(); dragString.DraggedString = returnedString; dragString.DragPointStart = Mouse.GetPosition(designer); DragDrop.DoDragDrop(this, dragString, DragDropEffects.Copy); } } }
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: this.window = ((ProcessCapture.ProcessLayoutWindow)(target)); #line 7 "..\..\ProcessLayoutWindow.xaml" this.window.Loaded += new System.Windows.RoutedEventHandler(this.Window_Loaded); #line default #line hidden #line 7 "..\..\ProcessLayoutWindow.xaml" this.window.Activated += new System.EventHandler(this.window_Activated); #line default #line hidden return; case 2: #line 21 "..\..\ProcessLayoutWindow.xaml" ((System.Windows.Controls.Grid)(target)).MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(this.MoveWindow); #line default #line hidden return; case 3: this.btnMinimize = ((System.Windows.Controls.Button)(target)); return; case 4: this.btnMaximize = ((System.Windows.Controls.Button)(target)); return; case 5: this.btnClose = ((System.Windows.Controls.Button)(target)); return; case 6: this.mygrid = ((System.Windows.Controls.Grid)(target)); return; case 7: this.tbToolBar = ((System.Windows.Controls.ToolBar)(target)); return; case 8: this.btnSave = ((System.Windows.Controls.Button)(target)); #line 55 "..\..\ProcessLayoutWindow.xaml" this.btnSave.Click += new System.Windows.RoutedEventHandler(this.btnSave_Click); #line default #line hidden return; case 9: this.screenShots = ((DiagramDesigner.Toolbox)(target)); return; case 10: this.drawingCanvas = ((DiagramDesigner.DesignerCanvas)(target)); return; } this._contentLoaded = true; }
public SelectionService(DesignerCanvas canvas) { this.designerCanvas = canvas; }
private void findParts() { if (eventsAdded) { this.designerCanvas.LayoutUpdated -= this.DesignerCanvas_LayoutUpdated; this.zoomThumb.DragDelta -= this.Thumb_DragDelta; this.zoomSlider.ValueChanged -= this.ZoomSlider_ValueChanged; eventsAdded = false; } if (this.ScrollViewer == null || !templateApplied) 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 += this.DesignerCanvas_LayoutUpdated; this.zoomThumb.DragDelta += this.Thumb_DragDelta; this.zoomSlider.ValueChanged += this.ZoomSlider_ValueChanged; eventsAdded = true; this.scaleTransform = new ScaleTransform(); this.designerCanvas.LayoutTransform = this.scaleTransform; this.designerCanvas.ScaleChanged += designerCanvas_ScaleChanged; }