public static ProcessUnitControl CreateOnCanvas(DrawingCanvas canvas, AbstractProcessUnit processUnit) { ProcessUnitControl pu = new ProcessUnitControl(canvas, processUnit); canvas.AddNewChild(pu); // Set the initial location pu.SetValue(Canvas.LeftProperty, processUnit.Location.X - pu.Width / 2.0); pu.SetValue(Canvas.TopProperty, processUnit.Location.Y - pu.Height / 2.0); // Make sure we have the right z-order pu.SetValue(Canvas.ZIndexProperty, 1); return(pu); }
public static StickyNoteControl CreateOnCanvas(DrawingCanvas canvas, StickyNote memNote, object commentParentControl) { // I'm using a static constructor because this way I can at least choose // wording that implies that this control will be created AND added to // the drawing canvas. // Quick parameter check if (null == canvas || null == memNote) { throw new ArgumentNullException(); } StickyNoteControl snc = new StickyNoteControl(canvas, memNote); snc.m_commentParent = commentParentControl; canvas.AddNewChild(snc); // Give it a high z-index since we want comments above everything else snc.SetValue(Canvas.ZIndexProperty, (int)4); // Setup extra stuff if we have a parent control if (null != commentParentControl) { if (!(commentParentControl is ChemProV.PFD.Streams.StreamControl) && !(commentParentControl is ProcessUnitControl)) { throw new InvalidOperationException( "The parent element for a comment-sticky-note must be a stream or process unit"); } // Create the line and add it to the drawing canvas snc.m_lineToParent = new Line(); canvas.AddNewChild(snc.m_lineToParent); snc.m_lineToParent.SetValue(Canvas.ZIndexProperty, -3); snc.m_lineToParent.Stroke = new SolidColorBrush(Color.FromArgb(255, 245, 222, 179)); snc.m_lineToParent.StrokeThickness = 1.0; // Make sure that when the parent moves we update the line if (commentParentControl is ProcessUnitControl) { (commentParentControl as ProcessUnitControl).ProcessUnit.PropertyChanged += snc.ProcessUnitParentPropertyChanged; } else { (commentParentControl as PFD.Streams.StreamControl).Stream.PropertyChanged += snc.StreamParentPropertyChanged; } // Position the line to the parent snc.UpdateLineToParent(); } // Hide if need be if (!memNote.IsVisible) { snc.Hide(); } return(snc); }