引言
要删除连接,只需监听来自连接器本身或编辑器的断开连接事件,并删除具有连接器作为源或目标的连接。为了简单起见,我们将为 NodifyEditor
实现 DisconnectConnectorCommand
。
1、编辑器
首先让我们将其添加到 EditorViewModel。
public class EditorViewModel
{
public ICommand DisconnectConnectorCommand { get; }
...
public EditorViewModel()
{
DisconnectConnectorCommand = new DelegateCommand<ConnectorViewModel>(connector =>
{
var connection = Connections.First(x => x.Source == connector || x.Target == connector);
connection.Source.IsConnected = false; // This is not correct if there are multiple connections to the same connector
connection.Target.IsConnected = false;
Connections.Remove(connection);
});
...
}
}
2、绑定到视图
<nodify:NodifyEditor ItemsSource="{Binding Nodes}"
Connections="{Binding Connections}"
PendingConnection="{Binding PendingConnection}"
DisconnectConnectorCommand="{Binding DisconnectConnectorCommand}">
...
</nodify:NodifyEditor>
按住ALT 鼠标点击链接端子解除连接