Skip to main content

Microsoft Silverlight

Answered Question How to expand item in TreeVeiwRSS Feed

(0)

juuunior
juuunior

Member

Member

2 points

9 Posts

How to expand item in TreeVeiw

  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;
 But "tvi"  is always null! Sad

lingbing
lingbing

Contributor

Contributor

2249 points

406 Posts

Re: How to expand item in TreeVeiw

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!

Ling Bing
Bei Jing University of Aeronautics and Astronautics
Bei Jing, China

JustinAngel
JustinAngel

Contributor

Contributor

4415 points

596 Posts

Answered Question

Re: How to expand item in TreeVeiw

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.

--
Justin Angel,
Blog @ http://silverlight.net/blogs/JustinAngel
Twitter @ http://twitter.com/JustinAngel
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities