Xam
Xam

Reputation: 311

Hide TreeView root node in WPF

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

Upvotes: 1

Views: 1681

Answers (2)

Walt Ritscher
Walt Ritscher

Reputation: 7047

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

Upvotes: 2

Mamta D
Mamta D

Reputation: 6460

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

Upvotes: 0

Related Questions