Consider the following collection.
- True
- False
- False
- False
- True
- True
- False
- False
I want to display it in a structured way, say, in a TreeView
. I want to be able to draw borders around entire groups and such.
- True Group
- True
- False Group
- False
- False
- False
- True Group
- True
- True
- False Group
- False
- False
How do I accomplish this with as little procedural code as possible?
You may wanna check out the pseudo TreeGrid on Delay's blog at http://blogs.msdn.com/delay/archive/2009/09/23/if-it-walks-like-a-duck-and-talks-like-a-duck-it-must-be-a-treegrid-a-simple-xaml-only-treegrid-ui-for-wpf.aspx
(source: msdn.com)
This does what you're looking for and is generic:
Usage:
Output:
While the code in the accepted answer meets the needs of the original question, it will fall over when handling IEnumerables of more complex objects (since the predicate will tend to throw an exception when comparing the last item in the enumerable with the "next" item [which, by definition, will always be null]).
This version handles more complex objects: