protected void UpdateAnchor(ClickTargetEnum anchorType, double left, double top) { foreach (FrameworkElement r in Anchors) { if ((ClickTargetEnum)r.Tag == anchorType) { Canvas.SetLeft(r, left); Canvas.SetTop(r, top); r.Width = AnchorSize; r.Height = AnchorSize; } } }
protected FrameworkElement AddAnchor(ClickTargetEnum anchorType, double left, double top) { FrameworkElement r; if (anchorType == ClickTargetEnum.AnchorRightTop_CreateDiagramLine) { TextBox l = new TextBox(); l.IsReadOnly = true; l.Focusable = false; l.Text = "*"; l.FontSize = 22; l.FontFamily = new FontFamily("Times New Roman"); l.Padding = new Thickness(-1.8, -3.5, 0, 0); l.Margin = new Thickness(0); l.BorderThickness = new Thickness(0); l.Background = (Brush)FindResource("0SelectionBrush"); l.Foreground = (Brush)FindResource("0BackgroundBrush"); r = l; } else { r = new Rectangle(); ((Rectangle)r).Fill = (Brush)FindResource("0SelectionBrush"); } Canvas.SetLeft(r, left); Canvas.SetTop(r, top); r.Width = AnchorSize; r.Height = AnchorSize; r.Tag = anchorType; Anchors.Add(r); r.MouseLeftButtonDown += AnchorMouseButtonDown; switch (anchorType) { case ClickTargetEnum.AnchorLeftTop: r.Cursor = Cursors.SizeNWSE; break; case ClickTargetEnum.AnchorMiddleTop: r.Cursor = Cursors.SizeNS; break; case ClickTargetEnum.AnchorRightTop_CreateDiagramLine: r.Cursor = Cursors.Pen; break; case ClickTargetEnum.AnchorLeftMiddle: r.Cursor = Cursors.SizeWE; break; case ClickTargetEnum.AnchorRightMiddle: r.Cursor = Cursors.SizeWE; break; case ClickTargetEnum.AnchorLeftBottom: r.Cursor = Cursors.SizeNESW; break; case ClickTargetEnum.AnchorMiddleBottom: r.Cursor = Cursors.SizeNS; break; case ClickTargetEnum.AnchorRightBottom: r.Cursor = Cursors.SizeNWSE; break; } Diagram.TheCanvas.Children.Add(r); return(r); }