For my first blog post I’m going to present a little pet project inspired by requests from some of our customers. And so, without further ado:
The Breadcrumb is a simple control that analyzes the type of the collection found in the RadGridView’s ItemsSource property and automatically resolves data hierarchies.
Usage is pretty straight-forward. Place the control anywhere you like and then connect it to the RadGridView, all in XAML. Example:
The logic behind the type analysis algorithm is simple: represent every collection as a generic IEnumerable<> and get the type of the generic argument. So if you have an array of objects of type SalesOrder in a property of the business object you use, the Breadcrumb is going to allow you to expand the row for the business object and reveal a nested grid displaying the related SalesOrder objects. And all this without coding the hierarchy relationships in XAML or code-behind.
The actual magic happens in the following method:
This method is a recursive function that first gets called on the type of the items in the RadGridView’s ItemsSource property. It cycles trough the properties of the supplied type to see if any of them is actually a collection and goes on until it finds a type without a property of type IEnumerable<>. Its purpose is to build a tree, which is later used to dynamically generate the hierarchy within the RadGridView.
You can grab the source code of the sample application (data courtesy of Blend Sample Data Inc.) and the control itself here.