I'm not posting any code here, because I'm just looking for the broad strokes for how the thing I'm doing could be best organized--not help troubleshooting. It's pretty clear to me what I am doing wrong--but I cannot see how to do it right.
I have what I would call an MVVM application. An actual programmer might call it something much uglier than that. I have a class, MainWindowViewModel, which gets bound to the window and contains all kinds of functions that do the things that the window needs
to do.
The most important property in the "MainWindowViewModel" is the AutoFilteredCollection<T>. There are 3. They contain the items to be displayed in a listview, Something Like
public AutoFilteredCollection<Dog> = DogCollection { get; set; }
public AutoFilteredCollection<Breed> = BreedCollection { get; set; }
public AutoFilteredCollection<Vet> = VetCollection { get; set; }
So Dog, Breed and Vet are related classes. But the most important thing they have in common is that they are in a SQLite database, and come into the model via Entity Framework. They also share an interface (IDBobject), which contains 2 properties: Name,
and isIgnored. AutoFilteredCollection<T> contains SourceCollection<T> and FilteredCollection<T>, which allow users to sift through dogs or vets or whatever is up at the moment based on properties. So SourceCollection is an IEnumerable<T>
with all of the objects, and FilteredCollection has the ones the user is looking for. But obviously the properties of dogs and vets are very different, so the interface can't really contain many of them.
It is very easy to bind the ListView ItemsSource directly to the FilteredCollection, or directly to on of the AutoFilteredCollections. But this bypasses the MainWindowViewModel, and so bypasses some of the functionality I've put into it. But switching between
the 3 AutoFilteredCollections has proved very difficult (for me) because of the <T>. It is just very difficult to swap 3 IEnumerables with different <T> in and out of the same listview without just setting the itemssource or datacontext of
the listview separately from the rest of the window.
I have spent a lot of time (A. Lot. Of. Time.) trying to do this by making everything AutoFilteredCollection<IDBObject>, but C# really doesn't seem to like that And the only way it works is if IDBobject has every single property users might
want to sort by, which is pointless.
I have also thought of abandoning trying to swap the different IEnumerable types into the listview and come up with some solution involving tabs.
So while this has all been a magnificent lesson in how IEnumerable<T> works, I was hoping that some professional could propose a really clean solution, or at least bless my tabs idea before I get too deep into it.