views:

52

answers:

1

Hi,I want to add items in treeviewi n WPF.I have function as

 public void SetTree(string Title,int Boxtype,int BoxNo )
        {
            sBoxType = "Group";
            TreeList items = TreeList.Load(Title, sBoxType, BoxNo);
            DataContext = items; 
        }

XAML Code of TreeView:

<TreeView Margin="16,275,18,312" x:Name="treeView1" ItemsSource="{Binding}" ItemTemplate="{StaticResource TreeItemTemplate}">
              </TreeView>

 <DataTemplate x:Key="TreeItemTemplate">
            <WrapPanel>
                <TextBlock Text="{Binding Path=Title}" /> 
                 <TextBlock Text="{Binding Path=Box}" />  
             </WrapPanel>
        </DataTemplate>

Actually i wan to TreeView ot display lik

+Group (header) 
      Controllersgroup   5 (Child items).

As multicolumn child items.But it dislay like

Controllersgroup5

+1  A: 

Instead of a regular DataTemplate you must use a HierarchicalDataTemplate and set it's ItemSource Property.

<HierarchicalDataTemplate ItemsSource="{Binding ChildItems}" />

like so.

Oggy