title: How to handle invalid cast from Observable Collection to Generic LIst
body: <p>I am trying delete from a Gridview.</p>
  
  <pre><code>if (this.gridView.SelectedItems.Count == 0)
  {
      return;
  }
  
  ObservableCollection&lt;Query&gt; itemsToRemove = new ObservableCollection&lt;Query&gt;();
  
  foreach (Query item in this.gridView.SelectedItems)
  {
      itemsToRemove.Add(item);
  }
  
  foreach (Query item in itemsToRemove)
  {
      //this line causes the invalid cast
      ((ObservableCollection&lt;Query&gt;)this.gridView.ItemsSource).Remove(item as Query);
  
      Code = item.CODE;
  }
  </code></pre>
  
  <p>Removal of items from the Gridview</p>
  
  <p>Invalid cast exception
  Unable to cast object of type 
  'System.Collections.Generic.List<code>1[Inventory.Query]' to type 'System.Collections.ObjectModel.ObservableCollection</code>1[Inventory.Query]'.</p>