I want to have ListView control which can be filled with one of a number of different object types (not mixed, always just one type). I would like to adjust the columns dynamically to correspond to the object type currently in the list.
I know I could do this programmatically (http://stackoverflow.com/questions/868204/adding-columns-programatically-to-listview-in-wpf) but I was wondering if I could define the different column descriptions (GridViews) in XAML as resources and then select the one I need at run-time when the object type changes?
Clarification I am using a ListView control which displays details in columns. The columns are defined like this:
<ListView x:Name="TheList">
<ListView.View>
<GridView>
<GridViewColumn Header="Columns" Width="80"/>
<GridViewColumn Header="Added" Width="80"/>
<GridViewColumn Header="Automatically" Width="100"/>
</GridView>
</ListView.View>
</ListView>
My question is: can I define a number of ListView.View sections and switch between them depending of the object type in the list? The list will only contain one type of object at one time. I just need to display a different set of attributes.
The replies I have received so far seem to assume that I have a simple list which contains a mixture of objects. That is not the case. What I am looking for is something like this:
Name Address Town
-----------------------------------------
Liz Buck House London
Angie Block House Berlin
and then to switch to something completely different
Town Population
------------------------------
London 123456
Swansea 65432
Perhaps I'm making this too complicated....