0

The problem:

I have a list of objects which have Date, Name, and Value Properties. Name and Date properties could be different or the same.

orange  2012-01-01  1
orange  2013-01-01  0

I'd like create a GridView with Headers (which are distinct dates) and rows

  Name   2012-01-01   2013-01-01
orange       1            0

As you see objects do not have properties like '2012-01-01', so simple binding will not help.

Question

How can I create a binding using column's name?

This I'd like to do with XAML or converters, without using UserControl's events

svick
  • 236,525
  • 50
  • 385
  • 514
Yuriy Vikulov
  • 2,469
  • 5
  • 25
  • 32

2 Answers2

1

Essentially what you need to do (as you've noticed) is create a list of objects with dynamic properties (that is, properties populated at runtime). The transformation itself is a pivot on Date, with a sum (?) across value, which you can perform using a GroupBy Linq query in your converter.

Now for the tricky part. Take a look at this answer:

Data binding dynamic data

You need to implement ICustomTypeDescriptor to implement dynamic properties. Good luck.

Community
  • 1
  • 1
McGarnagle
  • 101,349
  • 31
  • 229
  • 260
0

take your list of objects - create a new list of objects with your conditions. then simply put the new list as itemssource to a datagrid/itemscontrol.

blindmeis
  • 22,175
  • 7
  • 55
  • 74