SelectionAlignLine.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. using System.Windows;
  3. using System.Windows.Documents;
  4. using System.Windows.Media;
  5. namespace TeamAAS.FlowEditor.Controls
  6. {
  7. /// <summary>
  8. /// 对齐引导线装饰器 - 拖拽节点时显示对齐参考线
  9. /// </summary>
  10. public class SelectionAlignLine : Adorner
  11. {
  12. private readonly Point _start;
  13. private readonly Point _end;
  14. private static readonly Pen AlignPen;
  15. static SelectionAlignLine()
  16. {
  17. AlignPen = new Pen(new SolidColorBrush(Color.FromRgb(0xE6, 0xA7, 0x00)), 1.5)
  18. {
  19. DashStyle = DashStyles.Dash
  20. };
  21. AlignPen.Freeze();
  22. }
  23. public SelectionAlignLine(UIElement adornedElement, Point start, Point end)
  24. : base(adornedElement)
  25. {
  26. _start = start;
  27. _end = end;
  28. }
  29. protected override void OnRender(DrawingContext drawingContext)
  30. {
  31. base.OnRender(drawingContext);
  32. if (double.IsNaN(_start.X) || double.IsNaN(_start.Y) ||
  33. double.IsNaN(_end.X) || double.IsNaN(_end.Y))
  34. return;
  35. drawingContext.DrawLine(AlignPen, _start, _end);
  36. }
  37. }
  38. }