private void ClearGrid()
 {
     nodeGrid.Children.Clear();
     star      = null;
     end       = null;
     robotGrid = null;
     nodeLabels.Clear();
 }
        private void CreateNode(Node node, NodePosition place)
        {
            var nodeLabel = new NodeLabel {
                Name       = $"lbl{node.Position.X}i{node.Position.Y}",
                Id         = node.Id,
                Position   = node.Position,
                Visibility = Visibility.Visible,
                Width      = 25,
                Height     = 25,
                Background = new SolidColorBrush(Colors.Gray),
                Margin     = new Thickness(place.X, place.Y, 0, 0)
            };

            nodeLabel.MouseLeftButtonUp += NodeClick;
            nodeGrid.Children.Add(nodeLabel);
            nodeLabels.Add(nodeLabel);
        }
        private void NodeClick(object sender, MouseButtonEventArgs e)
        {
            var node = sender as NodeLabel;

            if (node == null || !robotGrid.IsInitialized)
            {
                return;
            }
            if (btnSetBlock.IsChecked ?? false)
            {
                var res = robotGrid.ToggleObsticle(node.Id);
                node.Background = res ? new SolidColorBrush(Colors.Red) : new SolidColorBrush(Colors.Gray);
                if (end != null && Equals(end, node))
                {
                    end = null;
                }
                else if (star != null && Equals(star, node))
                {
                    star = null;
                }
            }
            if (btnSetStart.IsChecked ?? false)
            {
                star            = node;
                node.Background = new SolidColorBrush(Colors.Green);
                robotGrid.MakeAvailable(node.Id);
                if (end != null && Equals(end, node))
                {
                    end = null;
                }
            }
            else if (btnSetEnd.IsChecked ?? false)
            {
                end             = node;
                node.Background = new SolidColorBrush(Colors.Blue);
                robotGrid.MakeAvailable(node.Id);
                if (star != null && Equals(star, node))
                {
                    star = null;
                }
            }
        }