title: Find selected WPF Listbox entries
body: <p>I've been trying iterate through the selected items of a listbox in WPF, with the following code;</p>
  
  <pre><code>        try
          {
              for (int i = 0; i &lt; mylistbox.SelectedItems.Count; i++)
              {
                  ListItem li = (ListItem)mylistbox.SelectedItems[i];
  
                  string listitemcontents_str = li.ToString();
              }
          }
          catch(Exception e)
          {
              // Error appears here
              string error = e.ToString();
          }
  </code></pre>
  
  <p>However I receive an invalid cast exception;</p>
  
  <p>System.InvalidCastException: Unable to cast object of type 'mylist' to type 'System.Windows.Documents.ListItem'.</p>
  
  <p>Is there a way around this?</p>