TreeView and DataBinding RRS feed

  • Question

  • Hello!


    I have a rather simple seeming problem, but unfortunately can't seem to find out the solution.


    In my small app I have a treeview.


    I bind a dataobject to it, which has both interfaces: IEnumerable AND INotifyPropertyChanged implemented.


    This object "Person" has a property "string Name" and a property "Person Children" (contains an ObservableCollection<Person> of course). The implementation of IEnumerable (GetEnumerator()) returns the enumerator of the Children collection.


    Lets say we have the following data-tree



    - Tommy

    - Susi


    - Antonio

    - whatever

    - Ralph

    When I bind this datastructure to my tree, it displays all items BUT the root item (which is "Mother").


    Of course I DO WANT this item to be displayed. now how can I achieve this?


    I wire up the binding like this:



    Person mother = new Person("Mother",null);

    ... adding the children...


    treeview.DataContext = mother;



    <TreeView x:Name="treeview" ItemsSource="{Binding}" />


    --> help?




    Friday, June 29, 2007 7:27 AM


All replies