ConnectorControl.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System.Windows;
  2. using TeamAAS.FlowEditor.Models;
  3. namespace TeamAAS.FlowEditor.Controls
  4. {
  5. /// <summary>
  6. /// 连接点控件 - 节点上的输入/输出端口
  7. /// </summary>
  8. public class ConnectorControl : System.Windows.Controls.Control
  9. {
  10. #region 依赖属性
  11. public static readonly DependencyProperty DirectionProperty =
  12. DependencyProperty.Register("Direction", typeof(PortDirection),
  13. typeof(ConnectorControl), new PropertyMetadata(PortDirection.Input));
  14. /// <summary>
  15. /// 端口方向(输入/输出)
  16. /// </summary>
  17. public PortDirection Direction
  18. {
  19. get => (PortDirection)GetValue(DirectionProperty);
  20. set => SetValue(DirectionProperty, value);
  21. }
  22. public static readonly DependencyProperty PortIndexProperty =
  23. DependencyProperty.Register("PortIndex", typeof(int),
  24. typeof(ConnectorControl), new PropertyMetadata(0));
  25. /// <summary>
  26. /// 端口索引(用于判断节点的多个输出端口)
  27. /// </summary>
  28. public int PortIndex
  29. {
  30. get => (int)GetValue(PortIndexProperty);
  31. set => SetValue(PortIndexProperty, value);
  32. }
  33. public static readonly DependencyProperty SideProperty =
  34. DependencyProperty.Register("Side", typeof(PortSide),
  35. typeof(ConnectorControl), new PropertyMetadata(PortSide.Left));
  36. /// <summary>
  37. /// 端口所在边
  38. /// </summary>
  39. public PortSide Side
  40. {
  41. get => (PortSide)GetValue(SideProperty);
  42. set => SetValue(SideProperty, value);
  43. }
  44. public static readonly DependencyProperty LabelProperty =
  45. DependencyProperty.Register("Label", typeof(string),
  46. typeof(ConnectorControl), new PropertyMetadata(null));
  47. /// <summary>
  48. /// 端口标签(如 True/False)
  49. /// </summary>
  50. public string Label
  51. {
  52. get => (string)GetValue(LabelProperty);
  53. set => SetValue(LabelProperty, value);
  54. }
  55. #endregion
  56. static ConnectorControl()
  57. {
  58. DefaultStyleKeyProperty.OverrideMetadata(typeof(ConnectorControl),
  59. new FrameworkPropertyMetadata(typeof(ConnectorControl)));
  60. }
  61. /// <summary>
  62. /// 获取所属的 FlowNode(通过 DataContext)
  63. /// </summary>
  64. public FlowNode GetNode()
  65. {
  66. return DataContext as FlowNode;
  67. }
  68. }
  69. }