title: Cast Datagrid.SelectedItems collection to List<T>
body: <p>I Have a class like this </p>
  
  <pre><code>public class Foo
  {
      public string prop1 {get;set;}
      public string prop2 {get;set;}
  }
  </code></pre>
  
  <p>And a view model with a <code>List&lt;Foo&gt;</code>, this list is used as a <code>Bind</code> of one <code>DataGrid</code>, then in the codebehind I need to get the  <code>Datagrid.SelectedItems</code> collection and convert it to <code>List&lt;Foo&gt;</code></p>
  
  <p>Things that i tryed: </p>
  
  <pre><code>List&lt;Foo&gt; SelectedItemsList= (List&lt;Foo&gt;)DataGrid.SelectedItems;
  // OR
  object p = DataGrid.SelectedItems;
  List&lt;Foo&gt; SelectedItemsList= ((IList)p).Cast&lt;Foo&gt;().ToList();
  </code></pre>
  
  <p>All this ways compile but throw an exception at run time. </p>
  
  <p>What is the proper way to cast it ? </p>
  
  <p><strong>NOTE:</strong> Base Type of <code>DataGrid</code> is an <code>ObservableCollection</code> does this made some diference ?</p>