using System.Windows;
using TeamAAS.FlowEditor.Models;
namespace TeamAAS.FlowEditor.Controls
{
///
/// 连接点控件 - 节点上的输入/输出端口
///
public class ConnectorControl : System.Windows.Controls.Control
{
#region 依赖属性
public static readonly DependencyProperty DirectionProperty =
DependencyProperty.Register("Direction", typeof(PortDirection),
typeof(ConnectorControl), new PropertyMetadata(PortDirection.Input));
///
/// 端口方向(输入/输出)
///
public PortDirection Direction
{
get => (PortDirection)GetValue(DirectionProperty);
set => SetValue(DirectionProperty, value);
}
public static readonly DependencyProperty PortIndexProperty =
DependencyProperty.Register("PortIndex", typeof(int),
typeof(ConnectorControl), new PropertyMetadata(0));
///
/// 端口索引(用于判断节点的多个输出端口)
///
public int PortIndex
{
get => (int)GetValue(PortIndexProperty);
set => SetValue(PortIndexProperty, value);
}
public static readonly DependencyProperty SideProperty =
DependencyProperty.Register("Side", typeof(PortSide),
typeof(ConnectorControl), new PropertyMetadata(PortSide.Left));
///
/// 端口所在边
///
public PortSide Side
{
get => (PortSide)GetValue(SideProperty);
set => SetValue(SideProperty, value);
}
public static readonly DependencyProperty LabelProperty =
DependencyProperty.Register("Label", typeof(string),
typeof(ConnectorControl), new PropertyMetadata(null));
///
/// 端口标签(如 True/False)
///
public string Label
{
get => (string)GetValue(LabelProperty);
set => SetValue(LabelProperty, value);
}
#endregion
static ConnectorControl()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(ConnectorControl),
new FrameworkPropertyMetadata(typeof(ConnectorControl)));
}
///
/// 获取所属的 FlowNode(通过 DataContext)
///
public FlowNode GetNode()
{
return DataContext as FlowNode;
}
}
}