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