开发者

TreeView Databinding

I want to add items开发者_如何学C 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


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

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

like so.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜