private static Task <EventArgs> PositionChanged(NodesControl nodesControl, NodeViewModel viewModel, string propertyName, Action action = null)
        {
            DoubleAnimation  speedDoubleAni = null;
            DependencyObject dObject        = nodesControl.ItemContainerGenerator.ContainerFromItem(viewModel);

            if (propertyName == nameof(NodeViewModel.X))
            {
                speedDoubleAni =
                    new DoubleAnimation(viewModel.OldX, (double)(viewModel.X), new Duration(new TimeSpan(0, 0, 3)));
                Storyboard.SetTargetProperty(speedDoubleAni, new PropertyPath(Canvas.LeftProperty));
            }
            if (propertyName == nameof(NodeViewModel.Y))
            {
                speedDoubleAni =
                    new DoubleAnimation(viewModel.OldY, (double)(viewModel.Y), new Duration(new TimeSpan(0, 0, 3)));

                Storyboard.SetTargetProperty(speedDoubleAni, new PropertyPath(Canvas.TopProperty));
            }

            Storyboard.SetTarget(speedDoubleAni, dObject);
            Storyboard story = new Storyboard();

            story.Children.Add(speedDoubleAni);


            story.Completed += (a, b) => nodesControl.Story_Completed(nodesControl);

            story.Begin();

            return(null);
        }
        private static void Reselect(NodesControl nodesControl, NodeViewModel viewModel)
        {
            foreach (var item in nodesControl.Items)
            {
                if (viewModel != ((NodeViewModel)item))
                {
                    (item as NodeViewModel).IsSelected = false;
                }
            }

            nodesControl.Dispatcher.InvokeAsync(() => nodesControl.SelectedObject = viewModel,
                                                System.Windows.Threading.DispatcherPriority.Background, default);
        }
        private void Story_Completed(NodesControl nodesControl)
        {
            bool removed = false;

            while (Removals.TryPop(out NodeViewModel pop))
            {
                removed |= (nodesControl.ItemsSource as ICollection <NodeViewModel>).ToList().Remove(pop);
            }

            if (removed)
            {
                var list = nodesControl.ItemsSource;
                nodesControl.ItemsSource = null;
                nodesControl.ItemsSource = list;
            }
        }
 public AddXCommand(NodesControl nodesControl)
 {
     this.nodesControl = nodesControl;
 }