A solution that may be even simpler than Reed Copsey's: Instead of messing around with the bindings of the ListView
s, create three different ListView
s, and have the buttons determine which one's visible. Whether I would do it this way or Reed's way depends primarily on things you haven't told us about yet.
Edit:
To answer your question, we're going to get out of "even more simple" territory, and into the territory of "why WPF is freaking awesome."
In fact, the more WPFish, MVVMish way to do things is to create a subclass for each of your three collection types - e.g. a type called CharactersCollection
that's a subclass of ObservableCollection<Character>
. Then add a DataTemplate
for each of these types to the resource dictionary:
<DataTemplate DataType="CharactersCollection">
<ListView ItemsSource="{Binding}">
<!-- specific column definitions for character information goes here -->
</ListView>
</DataTemplate>
Now, any time anything in WPF needs to render a CharactersCollection
, it'll find that template and use it.
In your view model class, you can create a property like this:
private object _ActiveCollection;
public object ActiveCollection
{
get { return _ActiveCollection; }
set
{
_ActiveCollection = value;
OnPropertyChanged("ActiveCollection");
}
}
Simple enough, right? Which collection is active? Once you've done this, anything that needs to present the ActiveCollection
property, like this:
<ContentControl Content="{Binding ActiveCollection}"/>
will render the active collection using the DataTemplate
that's appropriate for the type of active collection.
And since you've implemented INotifyPropertyChanged
, any time you set ActiveCollection
, its current value will be rendered with the appropriate template. So now all your buttons need to do is set a property on the object that's the source of the bindings. (Or be bound to Command
objects that do that, but let's walk before we run.)