title: How can I get an ItemsSource as an ObservableCollection<>?
body: <p>I'm trying to modify a property of a grid depending on whether or not there are any items in the <code>ObservableCollection&lt;&gt;</code> the <code>ItemsSource</code> is bound to. I currently have an event for <code>OnItemsSourceChanged</code> on the grid, but the problem is that <code>ItemsSource</code> is an object, and without casting it, I don't have access to the <code>CollectionChanged</code> event of the <code>ObservableCollection&lt;&gt;</code>.  The generic type of <code>ObservableCollection&lt;&gt;</code> is undetermined until runtime and can be many things.  </p>
  
  <p>I've tried casting it with <code>ItemsSource as ObservableCollection&lt;object&gt;</code>, but that returns null.  No luck with <code>ItemsSource as ObservableCollection&lt;dynamic&gt;</code>, either. Doing <code>ItemsSource as IEnumerable&lt;object&gt;</code> works surprisingly enough, but that still does not allow me to access the <code>CollectionChanged</code> event.  </p>
  
  <p>How can I cast my object to the underlying <code>ObservableCollection&lt;&gt;</code>? I'd prefer to avoid using reflection, but I'm not going to be picky here.</p>