Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit How to expand item in TreeVeiw
2 replies. Latest Post by JustinAngel on January 1, 2009.
(0)
juuunior
Member
2 points
9 Posts
12-29-2008 8:43 AM |
A try use this way:
treeViewSource.ItemsSource = items; FCUWS.Item it = items[0];
TreeViewItem tvi = treeViewSource.ItemContainerGenerator.ContainerFromItem(it) as TreeViewItem; if (tvi !=null) tvi.IsExpanded = true;
lingbing
Contributor
2249 points
406 Posts
01-01-2009 10:59 PM |
In fact before the TreeViewItem has expanded for one time, its children have not been generated. So that it container is null. When you have expanded the node once, this method will work.
I don't know other way to expand a TreeViewItem when page loaded or SelectionChanged, that is the TreeView control's limit, what a pity!
Regards!
JustinAngel
4415 points
596 Posts
01-01-2009 11:35 PM |
The Container are generated on the spot, they are generated when the visual tree is built.
You can register to the TreeView.Loaded event and execute the last 3 lines of code in there and you should access to the containers.