Hi, i've got following problem: i have to display tabular data in some kind of grid.
Say class A is a data item, with properties Foo and Bar, and i have a list of items List or sth like this. i want to display these items in a grid, where items with same Foo are in one column, and items with same Bar in one row. basic. simple. i thought?
My initial attempt was to create an ItemsControl, use a Grid as ItemsPanelTemplate, and an ItemsTemplate where i bound the Grid.Row and Grid.Column attached properties to A.Foo and A.Bar, using IValueConverters to associate a specific Foo with a specific Column, e.g. the converter would look up the Foo value in a kind of Columns array and return the proper index. The thing is, building the row and column defintions for Grid. As they are completely dynamic (i dont know at design time, which Foo's and Bar's will be in the source collection), i cannot define them in the xaml file. But at runtime, ItemsControl really doesnt provide access to the current ItemsPanel instance. The only way i found was a dirty way using VisualTreeHelper.GetChild, and i managed to get the ItemsPanel instance and create the needed Row- and ColumnDefinitions, but my ItemTemplate-d items just wouldn't be rendered in the right row and column, although my Converters returned the right column/row indices. Maybe i don't really understand how ItemsControl works internally, but the thing is, im out of ideas.
Someone suggested using ListView with a GridView, grouping my items of same Bar in another object, this would relieve me of creating the rows dynamicly, but creating the columns dynamicly seems quite complicated.
Does anyone have an idea or at least a hint? Did i miss something obvious?