Nodify学习 伍:添加移除连接控制器,设置节点初始位置 ...

打印 上一主题 下一主题

主题 872|帖子 872|积分 2616

前置

移除连接

要删除连接,只需监听来自连接器自己或编辑器的断开连接变乱,并删除具有连接器作为源或目标的连接。为了简朴起见,我们将为 NodifyEditor 实现 DisconnectConnectorCommand。首先让我们将其添加到 EditorViewModel。
 
  1. public class EditorViewModel
  2. {
  3.     public ICommand DisconnectConnectorCommand { get; }
  4. [code]...
  5. public EditorViewModel()
  6. {
  7.     DisconnectConnectorCommand = new DelegateCommand<ConnectorViewModel>(connector =>
  8.     {
  9.         var connection = Connections.First(x => x.Source == connector || x.Target == connector);
  10.         connection.Source.IsConnected = false;  将连接器属性设为false
  11.         connection.Target.IsConnected = false;
  12.         Connections.Remove(connection);
  13.     });
  14.   <nodify:NodifyEditor ItemsSource="{Binding Nodes}"
  15.                      Connections="{Binding Connections}"
  16.                      PendingConnection="{Binding PendingConnection}"
  17.                      DisconnectConnectorCommand="{Binding DisconnectConnectorCommand}">
  18.   ...
  19. <p></nodify:NodifyEditor></p>}
复制代码
}
[/code]
Xaml
  1. <nodify:NodifyEditor ItemsSource="{Binding Nodes}"
  2.                      Connections="{Binding Connections}"
  3.                      PendingConnection="{Binding PendingConnection}"
  4.                      DisconnectConnectorCommand="{Binding DisconnectConnectorCommand}">
  5.   ...
  6. <p></nodify:NodifyEditor></p>
复制代码
 
控制节点位置

如你所见,节点总是在屏幕的左上角。这是因为它们在图中的位置是 (0, 0)。让我们来改变这一点!
在 中添加一个 属性,类型为 ,并触发 变乱。NodeViewModelLocationSystem.Windows.PointPropertyChanged
  1. public class NodeViewModel : NotifyPropertyBase
  2. {
  3.      public string Title { get; set; }
  4. [code] private Point _location;
  5. public Point Location
  6. {
  7.      get => _location;
  8.      set => Set(ref _location, value);
  9. }
  10. public ObservableCollection<ConnectorViewModel> Input { get; set; } = new ObservableCollection<ConnectorViewModel>();
  11. public ObservableCollection<ConnectorViewModel> Output { get; set; } = new ObservableCollection<ConnectorViewModel>();
复制代码
}
[/code]
 
Xaml
  1. <nodify:NodifyEditor ItemsSource="{Binding Nodes}"
  2.                      Connections="{Binding Connections}"
  3.                      PendingConnection="{Binding PendingConnection}">
  4. [code]<nodify:NodifyEditor.ItemContainerStyle>
  5.     <Style TargetType="{x:Type nodify:ItemContainer}">
  6.         <Setter Property="Location"
  7.                 Value="{Binding Location}" />
  8.     </Style>
  9. </nodify:NodifyEditor.ItemContainerStyle>
  10. ...
复制代码
[/code]
现在你可以在构造节点时设置它们的位置。
源码

github:zt199510/NodifySamples (github.com)

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

正序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

水军大提督

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表