Q:

WPF Treeview Databinding with mixed collections

I am trying to proper bind several collection by using composite collection. 
Please point out my mistake
I am expecting something like

Car

Year

2014
2013

Name

Toyota        
Euro

Benz

But Instead I am getting

Car

2014
2013
Toyota
Benz

XAML:
<TreeView Margin="8" Grid.Row="2" Grid.RowSpan="2" Name="CarTree" >
    <TreeView.Resources>
        <HierarchicalDataTemplate DataType="{x:Type local:Car}" ItemsSource="{Binding Children}">
            <StackPanel>
                <TextBlock Text="{Binding Path=CarName}" />
            </StackPanel>
        </HierarchicalDataTemplate>
        <HierarchicalDataTemplate DataType="{x:Type local:Year}">
            <StackPanel>
                <TextBlock Text="{Binding Path=YearName}" />
            </StackPanel>
        </HierarchicalDataTemplate>
    </TreeView.Resources>
</TreeView>

Year Class: 
public class Year:ViewModelBase
{
    private string _yearname= String.Empty;
        public string YearName
        {
          get { return _yearname; }
          set
          {
            _yearname= value;
            OnPropertyChanged("YearName");
          }
        }
}

Car Class:
public class Car: ViewModelBase
{

    private string _carname= String.Empty;

    public string CarName
    {
        get { return _carname; }
        set
        {
            //ignore if values are equal
            if (value == _carname) return;

            _carname= value;
            OnPropertyChanged("CarName");
        }
    }

    private ObservableCollection<Year> _years=new ObservableCollection<Year>();

    public ObservableCollection<Year> Years
    {
        get { return _years; }
        set
        {
            //ignore if values are equal
            if (value == _years) return;

            _years= value;
            OnPropertyChanged("Years");
        }
    }
    public IList Children
    {
        get
        {
            return new CompositeCollection()
        {
            new CollectionContainer() { Collection = this.Years},
            new CollectionContainer() { Collection = ...},
            new CollectionContainer() { Collection =... }
        };
        }
    }

}

A:

Maybe you'd better not use hierarchical data templates as your data structure does not seem recursive.
But if you want to keep them you can do something like:
public class YearsCollection : ObservableCollection<Year>
{
}
...
YearsCollection _years = new YearsCollection();

public YearsCollection Years
{
    get { return _years; }
    set
    {
        //ignore if values are equal
        if (value == _years) return;

        _years = value;
        OnPropertyChanged("Years");
    }
}

public IList Children
{
    get
    {
        return new[]
        {
            this.Years
            ...
        };
    }
}

And add a template for each intermediate collection:
<HierarchicalDataTemplate DataType="{x:Type local:YearsCollection}" ItemsSource="{Binding}">
    <StackPanel>
        <TextBlock Text="Years" />
    </StackPanel>
</HierarchicalDataTemplate>

