0

我正在制作一个草药数据库程序,但在为我的主要数据类设置 HierarchicalDataTemplates 时遇到了麻烦。

想要的树形布局:

  • 词汇表
    • 类别1
      • 字母(减少整体列表大小)
        • 入口
          • 注1
          • 笔记2
  • 草药

    • 植物名称

      • 按字母顺序
        • 字母(减少整体列表大小)
          • 入口
      • 按家庭
        • 家庭
          • 入口
    • 通用名称

      • 字母(减少整体列表大小)
        • 入口

注意:所有条目都有注释 注意2:字母是用于排序的字母

前任:

  • 一种
    • 苹果
  • b
    • 公共汽车

主类:

Public Class MainSystem
    Public herbs As New Dictionary(Of Integer, herbEntry)
    Public glossary As New Dictionary(Of Integer, glossaryEntry)
End Class

词汇表条目:

Public Class glossaryEntry
    Public Property ID As Integer
    Public Property Words As List(Of String) 'Each word is in the format: Catagory/word
    Public Property Notes As SortedDictionary(Of String, String)
End Class

草药入口:

Public Class herbEntry
    Public ID As Integer
    Public Property commonName As List(Of String)
    Public Property botanicalName As List(Of String)
    Public Property PlantID As PlantID
End Class

编辑:感谢@AngelWPF 的链接,我得到了显示我的对象的树。但是,目前树看起来像这样:

  • 草药
    • 通用名称
      • 条目中的 CommonName 项
      • 条目中的另一个 CommonName 项目
    • 通用名称
      • 条目中的 CommonName 项
      • 条目中的另一个 CommonName 项目

如何进行此更改以匹配我的层次结构?

XAML:

<UserControl.Resources>
        <HierarchicalDataTemplate  DataType="{x:Type my:herbEntry}">
            <TreeViewItem Header="Common Name"  ItemsSource="{Binding commonName}">

            </TreeViewItem>
        </HierarchicalDataTemplate>
    </UserControl.Resources>
    <Grid>
        <TreeView HorizontalAlignment="Stretch" Name="TreeView1" VerticalAlignment="Stretch">
            <TreeViewItem Header="Herbs" ItemsSource="{Binding herbs.Values}"/>
        </TreeView>
    </Grid>
4

1 回答 1

0

这个例子可以指导您为每种类型的绑定项目分配不同级别的不同项目模板......

在 TreeView 中有 HierarchicalDataTemplates

于 2011-10-03T10:12:20.403 回答