title: Delete items from ListBox in WPF?
body: <p>I am trying to delete items from listbox which is data bound. 
  Here is the screenshot how listbox look like.</p>
  
  <p><a href="https://i.stack.imgur.com/lgCI9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lgCI9.png" alt="alt text"></a>
  </p>
  
  <p>This is the code which adds items in lists.</p>
  
  <pre><code>    public class Task
      {
          public string Taskname { get; set; }
  
          public Task(string taskname)
          {
              this.Taskname = taskname;
          }
      }
  
      public void GetTask()
      {
          taskList = new List&lt;Task&gt;
                             {
                                 new Task("Task1"),
                                 new Task("Task2"),
                                 new Task("Task3"),
                                 new Task("Task4")
                             };
  
          lstBxTask.ItemsSource = taskList;
      }
  </code></pre>
  
  <p>This is the Xaml code,</p>
  
  <pre><code> &lt;ListBox x:Name="lstBxTask" Style="{StaticResource ListBoxItems}" &gt;
          &lt;ListBox.ItemTemplate&gt;                
              &lt;DataTemplate&gt;
                  &lt;StackPanel Orientation="Horizontal"&gt;
                      &lt;TextBlock Text="{Binding Taskname}"  Style="{StaticResource TextInListBox}"/&gt;
                      &lt;Button Name="btnDelete" Style="{StaticResource DeleteButton}" Click="btnDelete_Click"&gt;
                      &lt;/Button&gt;                        
                  &lt;/StackPanel&gt;                    
              &lt;/DataTemplate&gt;
          &lt;/ListBox.ItemTemplate&gt;
      &lt;/ListBox&gt;
  </code></pre>
  
  <p>Whenever item in a listbox is selected, delete (x) button is displayed. When clicked it should delete that item from the listbox. Can anyone tell me how can I do this?</p>