When databinding a TreeView
, how would you create multiple levels of grouping for the items displayed?
Imagine you are binding to a Shop class which, among others, has the properties Region
and RetailChain
. The desired effect is to have a TreeView
that displays the shops in the following topology:
+ Region: California
| + Walmart
| + Walmart Pacific Beach
| + Walmart Orange County
| + Walmart San Diego
+ Region: New Jersey
+ Frys
| + Frys Electronics NJ
+ Walmart
+ Walmart New Jersey
The clincher is this: Region
s aren't related to Retailer
s, and vice versa, so the Shop
(the leaf node) is the only common denominator.
Using CollectionViewSource
only allows for a single level of grouping (despite the fact that the CollectionView
class has properties that suggest multi-level grouping).
Using the HierarchicalDataTemplate
only works for top-down topologies, which this scenario doesn't lend itself to.
Any suggestions on how to solve this?