views:

48

answers:

2

Hello I have a TreeView that I filled with a list of TreeViewItem from a collection (using the binding), I linked to a TreeView event "Expand" to expand it and display their childrens, my objective now is to get the last TreeViewItem accessed and to initialize the TreeView by the last treeViewItem consulted. I can retrieve the last TreeViewItem consulted and their childrens, but I can not expand it automatically. I use this method, but it returns always null.

TreeViewItem item =control.ItemContainerGenerator.ContainerFromItem(lastItem)as TreeViewItem; item.IsExpanded = true;

item is always null, isExpanded doses not work, and lastItem is a string(the text you see on the screen : is the treeViewItem.datacontext recovred ).

A: 

You should read this CodeProject article on TreeView MVVM approach which will simplify all your work with TreeView and TreeViewItem controls.

Eugene Cheverda
it seems very important thank you
A: 

I still have a problem with ItemContainerGenerator.ContainerFromItem it always returns null, MyTreeViewItem.ItemContainerGenerator.Status displays "not started", yet the TreeViewItem is displayed in the treeview. help because I am completely lost