My name is Edward Tanguay. I'm an American software and web developer living and working in Berlin, Germany.
yesterday: Inspiring ted talk: Sugata Mitra: The child-driven education: "any teacher who can be replaced by a machine, should be": http://is.gd/eZRvi.
yesterday: Always so painful to look up the German article of a borrowed IT word: der Framework or das Framework? LEO won't tell me: http://is.gd/eZMeU.
yesterday: I know what podcast I'm listening to tomorrow on my way to work: John Resig on technometria: http://is.gd/eZJfq.
yesterday: C# CODE EXAMPLE: Extension method to sort a generic collection of objects: http://is.gd/eZG6n.
yesterday: C# CODE EXAMPLE: A simple class that represents a matching quiz item: http://is.gd/eZFZV.
yesterday: After-work 13K, two 5Ks under sub-four marathon pace: 23:27, 27:27, legs feel great: http://tanguay.info/run.
yesterday: 6 yr old daughter's last 2 questions before falling asleep tonight: 1) Why are there humans? 2) Is there anything that doesn't have a name?
3 days ago: If you are a developer in Berlin and need to improve your English, I'm looking for groups to teach after work: http://tanguay.info/itenglish.
3 days ago: As far as I'm concerned, the singularity is already here, every time I wake up twitter tells me something amazing was created while I slept.
3 days ago: We're not suffering from information overload, we're suffering from faulty filtering.
3 days ago: Classic literature for free as nicely formatted 1-page or 2-page PDF downloads: http://www.planetebook.com/free-ebooks.asp.
WPF CODE EXAMPLE created on Wednesday, February 24, 2010 permalink
How to Create a TreeView with HierarchicalDataTemplate based on a collection of objects with collections
This example gives you the basics to display an object collection that has objects with collections of those objects recursively down to any level.
XAML:
<Window x:Class="TestTr32322.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:TestTr32322"
    Title="Window1" Height="300" Width="350">
    <Window.Resources>
        <HierarchicalDataTemplate x:Key="sectionTemplate"
            ItemsSource="{Binding ChildSections}"
            DataType="{x:Type local:Section}">
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding Title}" />
                <TextBlock Text=" - " />
                <TextBlock Text="{Binding Description}" FontStyle="Italic" Foreground="#777" />
            </StackPanel>
        </HierarchicalDataTemplate>
    </Window.Resources>
    <StackPanel>
        <TreeView ItemsSource="{Binding Sections}"
                    SelectedItemChanged="TreeView_SelectedItemChanged"
                    ItemTemplate="{StaticResource sectionTemplate}">
        </TreeView>
        <TextBlock Text="{Binding Message}" Margin="0 10 0 0"/>
    </StackPanel>
</Window>

Code Example:
using System.Windows;
using System.ComponentModel;
using System.Collections.ObjectModel;
using System.Windows.Controls;
using System;

namespace TestTr32322
{
    public partial class Window1 : Window, INotifyPropertyChanged
    {
        #region ViewModelProperty: Sections
        private ObservableCollection<Section> _sections = new ObservableCollection<Section>();
        public ObservableCollection<Section> Sections
        {
            get
            {
                return _sections;
            }

            set
            {
                _sections = value;
                OnPropertyChanged("Sections");
            }
        }
        #endregion test

        #region ViewModelProperty: Message
        private string _message;
        public string Message
        {
            get
            {
                return _message;
            }

            set
            {
                _message = value;
                OnPropertyChanged("Message");
            }
        }
        #endregion test



        public Window1()
        {
            InitializeComponent();
            DataContext = this;

            Sections = Section.GetSections();
        }

        #region INotifiedProperty Block
        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;

            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        #endregion test

        private void TreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
        {
            TreeView tw = ((TreeView)sender);
            Section selectedSection = tw.SelectedItem as Section;

            Message = String.Format("You choose {0} (Id={1})", selectedSection.Title, selectedSection.Id);

        }
    }

    public class Section : INotifyPropertyChanged
    {
        public int Id { get; set; }
        public string Title { get; set; }
        public string Description { get; set; }

        #region ViewModelProperty: ChildSections
        private ObservableCollection<Section> _childsections = new ObservableCollection<Section>();
        public ObservableCollection<Section> ChildSections
        {
            get
            {
                return _childsections;
            }

            set
            {
                _childsections = value;
                OnPropertyChanged("ChildSections");
            }
        }
        #endregion test


        public static ObservableCollection<Section> GetSections()
        {
            ObservableCollection<Section> sections = new ObservableCollection<Section>();
            {
                sections.Add(new Section {Id = 1, Title = "First Section", Description = "first description" });
                sections.Add(new Section { Id = 2, Title = "Second Section", Description = "second description" });
                sections.Add(new Section { Id = 3, Title = "Third Section", Description = "third description" });

                ObservableCollection<Section> grandchildren = new ObservableCollection<Section>();
                grandchildren.Add(new Section { Id = 5, Title = "Grandchild Section 1", Description = "grandchild description" });
                grandchildren.Add(new Section { Id = 6, Title = "Grandchild Section 2", Description = "grandchild description" });

                Section section = new Section();
                section.Id = 4;
                section.Title = "Fourth Section";
                section.Description = "fourth description";
                section.ChildSections.Add(new Section
                {
                    Id = 7,
                    Title = "Child Section",
                    Description = "this is a child description",
                    ChildSections = grandchildren
                });
                sections.Add(section);
            }

            return sections;
        }

        #region INotifiedProperty Block
        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;

            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        #endregion test
    }
}
need markup?