分层数据结构 WPF TreeListView DataTriggers [英] Hierarchical Data Structure WPF TreeListView DataTriggers

查看:42
本文介绍了分层数据结构 WPF TreeListView DataTriggers的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个树形列表视图,该视图显示与父级相比不同的信息.

I am trying to make a tree list view that displays different information compared to the parent.

根据我现在的情况,子级显示与父级相同的信息.我想知道,我将如何做到这一点.我的最后一个帖子对我来说并不是很有意义,它并没有很好地工作.我想知道是否有人可以为我更深入地解释一下.

From what I have now, the Children display the same information as the parent. I was wondering, how I would do this. The last post I had didn't really quite make sense to me, it didn't work really well. I was wondering if anyone can explain this a little more in depth for me.

这是最后一个帖子:

分层数据结构 WPF TreeListView

<r:TreeListView x:Name="TimeSheetsTreeListView" Margin="0,-18.312,0,0"
                Style="{DynamicResource TreelistStyle}"  Width="Auto" MinHeight="150" 
                Grid.Row="0" Background="#00FFFFFF"
                ItemsSource="{Binding TimeSheetItems, Mode=Default}"
                HorizontalContentAlignment="Center"
                VerticalAlignment="Top" Height="207.446" Foreground="White"
                Grid:GridViewSort.AutoSort="True" >
    <r:TreeListView.Columns>        
        <GridViewColumn DisplayMemberBinding="{Binding ClientMatterName}" Width="200" 
                        Grid:GridViewSort.PropertyName="ClientMatterName" >
            <GridViewColumnHeader HorizontalContentAlignment="Center" Foreground="White"
                                  Content="Client Name/Matter Name"
                                  Grid:GridViewSort.PropertyName="ClientMatterName"
        </GridViewColumn>            
        <GridViewColumn  DisplayMemberBinding="{Binding ClientMatterCode}" Width="200"
                         Grid:GridViewSort.PropertyName="ClientMatterCode" >
      <GridViewColumnHeader HorizontalContentAlignment="Center" Foreground="White"
                                  Content="Client No./Matter No." FontSize="10.667"/>
        </GridViewColumn>
        <GridViewColumn DisplayMemberBinding="{Binding TimeCode.Code}" Width="100"
                        Grid:GridViewSort.PropertyName="TimeCodeCode" >
            <GridViewColumnHeader HorizontalContentAlignment="Center" Foreground="White"
                                  Content="Time Code" FontSize="10.667"/>
        </GridViewColumn>
        <GridViewColumn Header="Hours" Width="100" Grid:GridViewSort.PropertyName="Hours">
            <GridViewColumn.CellTemplate>
                <DataTemplate>
                    <TextBlock HorizontalAlignment="Left"
                               Text="{Binding Duration, Converter={StaticResource BillableHoursConverter}}" />
                </DataTemplate>
            </GridViewColumn.CellTemplate>          
        </GridViewColumn>
        <GridViewColumn Width="300" DisplayMemberBinding="{Binding Description}"
                        Grid:GridViewSort.PropertyName="Description">
            <GridViewColumnHeader HorizontalContentAlignment="Center" Foreground="White"
                                  Content="Description" FontSize="10.667"/>
        </GridViewColumn>
    </r:TreeListView.Columns>
    <r:TreeListView.Resources>
        <HierarchicalDataTemplate DataType="{x:Type data:TimeSheet}"
                                  ItemsSource="{Binding Path= TimeRecords}"/>
    </r:TreeListView.Resources>
</r:TreeListView>

推荐答案

如果要在树视图中显示父子关系.(只有一层深,所以孩子都是叶节点).您将树视图绑定到父元素的集合.然后你为父级做一个分层的数据模板,为子级做一个标准的数据模板

if you want to display a parent-child relationship in a treeview. (only one level deep, so the children are all leaf nodes). you bind the treeview to the collection of parent elements. then you do a hierarchical data template for the parent, and a standard data template for the child

在您提供的示例中,您有一个对象类型 信息 的父对象,其中包含一组子对象类型 detaildetail 的集合父级上的(子级)称为 child

in the example you give you have a Parent of object type information with a collection of children object type detail and the collection of detail (children) on the parent is called child

所以我们为孩子们制作了一个模板,然后为父母制作了一个模板

so we do a template for the children, and then one for the parent

  <!--Child (detail) DataTemplate-->
  <DataTemplate
     DataType="{x:Type local:detail}">
     <TextBox Text="{Binding Path=Some child binding}"/>
  </DataTemplate>

  <!--Parent (information) Hierarchical Template-->
  <HierarchicalDataTemplate
     DataType="{x:Type local:information}"
     ItemsSource="{Binding Path=Child}">
     <TextBox Text="{Binding Path=Some parent binding}"/>
  </HierarchicalDataTemplate>

因为父和子是不同的对象类型,树视图将抓取父模板,它有一个项目源,当绘制子时它将使用子数据模板.请注意,所有数据模板都没有键,它们以对象类型为键.

because the parent and child are of a different object type, the tree view will grab the parent template, which has an items source and when it comes to draw the children it will use th child data template. note none of the data templates have keys, they are keyed on their object type.

这篇关于分层数据结构 WPF TreeListView DataTriggers的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆