private void edit_click(object sender, RoutedEventArgs e)
 {
     if (listBox1.SelectedItem != null)
     {
         Task     selectedItem = this.listBox1.SelectedItem as Task;
         editTask Task         = new editTask(selectedItem);
         Task.ShowDialog();
         listBox1.Items.Refresh();
     }
     else
     {
         NoItemSelected error = new NoItemSelected();
         error.ShowDialog();
     }
 }
        private void DeleteButton_Click(object sender, RoutedEventArgs e)

        {
            if (listBox1.SelectedItem != null)
            {
                var itemSelected = listBox1.SelectedIndex;
                RequestWebApi.DeleteTask(ListItems[itemSelected].Id);
                ListItems.RemoveAt(itemSelected);
            }
            else
            {
                NoItemSelected error = new NoItemSelected();
                error.ShowDialog();
            }
        }
        private void up_click(object sender, RoutedEventArgs e)
        {
            if (listBox1.SelectedItem != null)
            {
                var selectedIndex = listBox1.SelectedIndex;

                if (selectedIndex > 0)
                {
                    var itemToMoveUp = this.ListItems[selectedIndex];
                    ListItems.RemoveAt(selectedIndex);
                    this.ListItems.Insert(selectedIndex - 1, itemToMoveUp);
                    this.listBox1.SelectedIndex = selectedIndex - 1;
                }
            }
            else
            {
                NoItemSelected error = new NoItemSelected();
                error.ShowDialog();
            }
        }
        private void down_click(object sender, RoutedEventArgs e)
        {
            if (listBox1.SelectedItem != null)
            {
                var selectedIndex = this.listBox1.SelectedIndex;

                if (selectedIndex + 1 < this.ListItems.Count)
                {
                    var itemToMoveDown = this.ListItems[selectedIndex];
                    this.ListItems.RemoveAt(selectedIndex);
                    this.ListItems.Insert(selectedIndex + 1, itemToMoveDown);
                    this.listBox1.SelectedIndex = selectedIndex + 1;
                }
            }
            else
            {
                NoItemSelected error = new NoItemSelected();
                error.ShowDialog();
            }
        }