I am attempting to create a ListView control which is populated via a binding to an ObservableCollection, which itself contains another ObservableCollection from which I need to display data in the ListView.
To clarify I have an object hierarchy as follows:
ClassA
{
int ID = 123;
string Name = "Value";
}
ClassB
{
int ID = 456;
ObservableCollection<ClassA> CollectionOfClassA;
}
ClassC
{
int ID = 789;
ObservableCollection<ClassB> CollectionOfClassB;
}
From this I would like to end up with the following ListView layout:
(ClassC.CollectionOfClassB ListView)
+-------------+-------------+------------------+--------------------------------+
| ClassB.ID | CollectionOfClassA.ClassA.ID | CollectionOfClassA.ClassA.ID |
+-------------+-------------+------------------+--------------------------------+
| ClassB.ID | CollectionOfClassA.ClassA.ID | CollectionOfClassA.ClassA.ID |
+-------------+-------------+------------------+--------------------------------+
To achieve this I would assume I need to bind my ListView to my CollectionOfClassB collection, however, the datatemplate structure and subsequent binding for producing the rows has me a bit stumped.
Can anyone assist me with this please?
Many thanks,
Edit:
The first column in the table above references the ID field for the indexed object in the ClassC.CollectionOfClassB collection, each row being an individual object stored in the CollectionOfClassB.
Each of the ClassB objects stored in CollectionOfClassB has its own CollectionOfClassA, which I am attempting to place in the listview on the same row as its parent. Each ClassA object in CollectionOfClassA being a column.
Edit 2:
The first column is populated by the ID field from ClassB for the current item in the CollectionOfClassB, the subsequent columns are populated with data from each item in the CollectionOfClassA. The column header would be ClassA.ID, whilst the content would be ClassA.Name for example.
I am looking for example XAML markup that will allow me to achieve this.
If you know that
ClassB.CollectionOfClassAis always the same length, you can bind to an indexed value of itHere’s a rough example
If you have a dynamic number of columns, it becomes a bit trickier
The simplest way would be to use a custom column and display the items in something like a horizontal
StackPanelOf course, this doesn’t use the built-in GridView features like sorting