private async void Delite_Click(object sender, RoutedEventArgs e)
        {
            cnv.Children.Clear();
            TreeCommands tc = new TreeCommands();

            if (((Vertexcs)Add.DataContext).Probability != 0)
            {
                List <Vertexcs> d = DeliteVertexes((Vertexcs)Add.DataContext);
                d.Add((Vertexcs)Add.DataContext);
                await tc.DeliteVerTex(d);

                vert = await tc.GiveALlVertex();
            }
            Button but = new Button();

            but.HorizontalAlignment = HorizontalAlignment.Left;
            but.VerticalAlignment   = VerticalAlignment.Top;
            but.Margin      = new Thickness(Widht / 2 - 10, 50, Widht / 2 - 10, Height - 70);
            but.Background  = new ImageBrush(new BitmapImage(new Uri(pathplus)));
            Back.Background = new ImageBrush(new BitmapImage(new Uri(path)));
            but.DataContext = FirstVer;
            but.Height      = 20;
            but.Width       = 20;
            but.Click      += But_Click;
            cnv.Children.Add(but);
            DrawRootVertexes(FirstVer);
            CostCurrentBranch(FirstVer, 0);
            DrawMaxDangerous();
        }
        private async void Window_Activated(object sender, EventArgs e)
        {
            if (flag)
            {
                Widht  = cnv.ActualWidth;
                Height = cnv.ActualHeight;

                DataCommands dc = new DataCommands();
                SelectedRisks = await dc.GiveAllRisks(project);

                if (SelectedRisks == null)
                {
                    SelectedRisks = new List <Risk>();
                }
                Drawing();
                TreeCommands tc = new TreeCommands();
                vert = await tc.GiveALlVertex();

                FirstVerTex = await tc.GiveFristVertex(drisk.Id);

                GiveTitle();
                CreateFirstVertex();
                CostCurrentBranch(FirstVerTex, 0);
                DrawMaxDangerous();
                WriteInListView();
                flag = false;
            }
        }
        private async void Window_Activated(object sender, EventArgs e)
        {
            if (flag)
            {
                try
                {
                    Widht  = cnv.ActualWidth;
                    Height = cnv.ActualHeight;
                    Label lab = new Label();
                    lab.HorizontalAlignment = HorizontalAlignment.Center;
                    lab.VerticalAlignment   = VerticalAlignment.Top;
                    lab.Content             = drisk.RiskName;
                    grid.Children.Add(lab);
                    TreeCommands tc  = new TreeCommands();
                    Button       but = new Button();
                    but.HorizontalAlignment = HorizontalAlignment.Left;
                    but.VerticalAlignment   = VerticalAlignment.Top;
                    but.Margin      = new Thickness(Widht / 2 - 10, 50, Widht / 2 - 10, Height - 70);
                    but.Background  = new ImageBrush(new BitmapImage(new Uri(pathplus)));
                    Back.Background = new ImageBrush(new BitmapImage(new Uri(path)));
                    Back.Foreground = new ImageBrush(new BitmapImage(new Uri(path)));
                    if (!await tc.Exist(drisk.Id))
                    {
                        FirstVer = new Vertexcs(drisk.Id, drisk.RiskName, Widht / 2, 50);
                        await tc.IsertNewVertex(FirstVer, drisk.Id);

                        FirstVer = await tc.GiveFristVertex(drisk.Id);

                        but.DataContext = FirstVer;
                    }
                    else
                    {
                        FirstVer = await tc.GiveFristVertex(drisk.Id);

                        but.DataContext = FirstVer;
                    }
                    but.Height = 20;
                    but.Width  = 20;
                    but.Click += But_Click;
                    cnv.Children.Add(but);
                    vert = await tc.GiveALlVertex();

                    DrawRootVertexes(FirstVer);
                    CostCurrentBranch(FirstVer, 0);
                    DrawMaxDangerous();
                    flag = false;
                }
                catch (NullReferenceException ex)
                {
                    MessageBox.Show(ex.Message);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }