WPF and Silverlight Edition Basic Library / TreeView / TreeView Elements
TreeView Elements

The C1TreeView class is a StackPanel with two elements:

C1TreeViewItems can be added to the C1TreeView control as static items defined either in the XAML or in the code behind or can be defined on your page or user control by using any of the following methods:

 

Each node in the Tree is represented by a name/value pair, defined by the text and value properties of treenode, respectively. The text of a node is rendered, whereas the value of a node is not rendered and is typically used as additional data for handling postback events.

A static menu is the simplest way to create the treeview structure.

To display static C1TreeViewItems using XAML syntax, first nest opening and closing <c1:C1TreeViewItem > tags between opening and closing tags of the C1TreeView control. Next, create the treeview structure by nesting <c1:C1TreeViewItem> elements between opening and closing <c1:C1TreeViewItem> tags. Each <c1:C1TreeViewItem> element represents a node in the control and maps to a C1TreeViewItem object.

Declarative syntax can be used to define the C1TreeViewItems inline on your page.

For example:

XAML
Copy Code
<Grid x:Name="LayoutRoot"> 
   <c1:C1TreeView x:Name="Tree"> 
       <c1:C1TreeViewItem Header="Book List" IsExpanded="True" IsSelected="True">
           <c1:C1TreeViewItem Header="Language Books"/>
           <c1:C1TreeViewItem Header="Security Books"/>
           <c1:C1TreeViewItem Header="Classic Books">
               <c1:C1TreeViewItem Header="Catch-22"/>
               <c1:C1TreeViewItem Header="The Great Gatsby"/>
           </c1:C1TreeViewItem>
       </c1:C1TreeViewItem>
   </c1:C1TreeView>
</Grid>

 Adding Images

You can add images to a node by grabbing its first child (the header), casting that to a StackPanel, and inserting an image element at whatever position you prefer. For example:

Code
Copy Code
StackPanel nodeHeader = TreeNode.Children[0] as StackPanel;
nodeHeader.Children.Insert(0, myImage);