title: Remove SelectedItems from a ListBox via MVVM RelayCommand
body: <p>I have a list of items in a WPF ListBox. I want to allow the user to select several of these items and click a Remove button to eliminate these items from the list.</p>
  
  <p>Using the MVVM RelayCommand pattern, I've created a command with the following signature:</p>
  
  <pre><code>public RelayCommand&lt;IList&gt; RemoveTagsCommand { get; private set; }
  </code></pre>
  
  <p>In my View, I wire up my RemoveTagsCommand like this:</p>
  
  <pre><code>&lt;DockPanel&gt;
  &lt;Button DockPanel.Dock="Right" Command="{Binding RemoveTagsCommand}" CommandParameter="{Binding ElementName=TagList, Path=SelectedItems}"&gt;Remove tags&lt;/Button&gt;
  &lt;ListBox x:Name="TagList" ItemsSource="{Binding Tags}" SelectionMode="Extended"&gt;
      &lt;ListBox.ItemsPanel&gt;
          &lt;ItemsPanelTemplate&gt;
              &lt;StackPanel Orientation="Horizontal"/&gt;
          &lt;/ItemsPanelTemplate&gt;
      &lt;/ListBox.ItemsPanel&gt;
      &lt;ListBox.Resources&gt;
          &lt;DataTemplate DataType="{x:Type Model:Tag}"&gt;
              ...
          &lt;/DataTemplate&gt;
      &lt;/ListBox.Resources&gt;
  &lt;/ListBox&gt;
  &lt;/DockPanel&gt;
  </code></pre>
  
  <p>My ViewModel constructor sets up an instance of the command:</p>
  
  <pre><code>RemoveTagsCommand = new RelayCommand&lt;IList&gt;(RemoveTags, CanRemoveTags);
  </code></pre>
  
  <p>My current implementation of RemoveTags feels clunky, with casts and copying. Is there a better way to implement this?</p>
  
  <pre><code>    public void RemoveTags(IList toRemove)
      {
          var collection = toRemove.Cast&lt;Tag&gt;();
          List&lt;Tag&gt; copy = new List&lt;Tag&gt;(collection);
  
          foreach (Tag tag in copy)
          {
              Tags.Remove(tag);
          }
      }
  </code></pre>