开发者

TreeView Databinding

开发者 https://www.devze.com 2022-12-26 21:00 出处:网络
I want to add items开发者_如何学C in treeviewi n WPF.I have function as public void SetTree(string Title,int Boxtype,int BoxNo )

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

精彩评论

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