前置
移除连接
要删除连接,只需监听来自连接器自己或编辑器的断开连接变乱,并删除具有连接器作为源或目标的连接。为了简朴起见,我们将为 NodifyEditor 实现 DisconnectConnectorCommand。首先让我们将其添加到 EditorViewModel。
- public class EditorViewModel
- {
- public ICommand DisconnectConnectorCommand { get; }
- [code]...
- public EditorViewModel()
- {
- DisconnectConnectorCommand = new DelegateCommand<ConnectorViewModel>(connector =>
- {
- var connection = Connections.First(x => x.Source == connector || x.Target == connector);
- connection.Source.IsConnected = false; 将连接器属性设为false
- connection.Target.IsConnected = false;
- Connections.Remove(connection);
- });
- <nodify:NodifyEditor ItemsSource="{Binding Nodes}"
- Connections="{Binding Connections}"
- PendingConnection="{Binding PendingConnection}"
- DisconnectConnectorCommand="{Binding DisconnectConnectorCommand}">
- ...
- <p></nodify:NodifyEditor></p>}
复制代码 }
[/code]
Xaml- <nodify:NodifyEditor ItemsSource="{Binding Nodes}"
- Connections="{Binding Connections}"
- PendingConnection="{Binding PendingConnection}"
- DisconnectConnectorCommand="{Binding DisconnectConnectorCommand}">
- ...
- <p></nodify:NodifyEditor></p>
复制代码
控制节点位置
如你所见,节点总是在屏幕的左上角。这是因为它们在图中的位置是 (0, 0)。让我们来改变这一点!
在 中添加一个 属性,类型为 ,并触发 变乱。NodeViewModelLocationSystem.Windows.PointPropertyChanged- public class NodeViewModel : NotifyPropertyBase
- {
- public string Title { get; set; }
- [code] private Point _location;
- public Point Location
- {
- get => _location;
- set => Set(ref _location, value);
- }
- public ObservableCollection<ConnectorViewModel> Input { get; set; } = new ObservableCollection<ConnectorViewModel>();
- public ObservableCollection<ConnectorViewModel> Output { get; set; } = new ObservableCollection<ConnectorViewModel>();
复制代码 }
[/code]
Xaml- <nodify:NodifyEditor ItemsSource="{Binding Nodes}"
- Connections="{Binding Connections}"
- PendingConnection="{Binding PendingConnection}">
- [code]<nodify:NodifyEditor.ItemContainerStyle>
- <Style TargetType="{x:Type nodify:ItemContainer}">
- <Setter Property="Location"
- Value="{Binding Location}" />
- </Style>
- </nodify:NodifyEditor.ItemContainerStyle>
- ...
复制代码 [/code]
现在你可以在构造节点时设置它们的位置。
源码
github:zt199510/NodifySamples (github.com)
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |