ListBox Item Removal

后端 未结 5 1462
长发绾君心
长发绾君心 2021-01-14 19:15

I have a WPF window that manages sets of configurations and it allows users to edit a configuration set (edit button) and to remove a configuration set (remove button). The

5条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-14 20:09

    use:

    private void RemoveButton_Click(object sender, RoutedEventArgs e)
    {
      foreach(ConfigSet item in this.configSetListBox.SelectedItems)
      {
          this.configSetListBox.ItemsSource.Remove(item); // ASSUMING your ItemsSource collection has a Remove() method
      }
    }
    

    Note: my use of this. is just so it as it is more explicit - it also helps one see the object is in the class namespace as opposed to variable in the method we are in - though it is obvious here.

提交回复
热议问题