views:

82

answers:

2

Hello,

Can someone tell me how to hide the root node of a TreeView in WPF/Silverlight? I would still like to display hierarchical data and to be able to expand collapse nodes except for the root node (which shouldn't be displayed at all).

Regards,

Xam

A: 

You can create a DataTrigger that makes the root node collapsed

This link may help: http://www.beacosta.com/2006/05/how-can-i-change-way-data-_114702952170041155.html

Mamta Dalal
@Mamta: If I collapse the root node, won't that make all other nodes disappear too?
Xam
+1  A: 

Do you need to have a single root node?

If not you could create all your items at the top level.


<TreeView>
  <TreeViewItem Header='First'>
    <TreeViewItem Header='sub' />
  </TreeViewItem>
  <TreeViewItem Header='Second'>
    <TreeViewItem Header='sub' />
  </TreeViewItem>
  <TreeViewItem Header='Third'>
    <TreeViewItem Header='sub' />
  </TreeViewItem>
</TreeView>

alt text

Walt Ritscher