Hierarchy via collection view grouping

Aug 3, 2009 at 7:28 PM

I've just started working with this API in the hope of using it in my application.  It looks very well written and has taught me a few new things about WPF.  Thanks.

Ideally I'd like to set the ItemsSource on a TreeMaps control and control the hierarchy via CollectionViewSource.GroupDescriptions (http://msdn.microsoft.com/en-us/library/system.windows.data.collectionviewsource.groupdescriptions.aspx).

I understand that the current approach is to create a HierarchicalDataTemplate, but this requires that the underlying data be hierarchical.  This also requires my code to perform summing of weights to parents.

For example, I have an Order object with Sector, Exchange, Size, and ExecPercent properties.  I would like to bind it via a CollectionViewSource:

  <CollectionViewSource Source="{Binding Path=Orders}" x:Key="OrdersSource">
      <dat:PropertyGroupDescription PropertyName="Exchange"/>

  <TreeMaps ItemsSource="{StaticResource OrdersSource}" ValuePropertyName="Size" />

This means the user could change the group property from exchange to sector, for example.  This would also create a group name to display in the group template, maybe as an overlay or to the top.  Similarly, the user could change the ValuePropertyName at runtime.

Can someone provide some information about how this could be done?  Or, more importantly, any reason why this would not be possible before I start trying to code this myself.


Drew Noakes