用于非常复杂布局的 HierarchicalDataTemplate
我正在制作一个草药数据库程序,但在为我的主数据类设置 HierarchicalDataTemplates 时遇到了麻烦。
需要树形布局:
- 术语表
- 类别1
- 信件(减少整体列表大小)
- 条目
- 注1
- 注2
- 条目
- 信件(减少整体列表大小)
- 类别1
草药
植物名称
- 按字母顺序
- 信件(减少整体列表大小)
- 条目
- 信件(减少整体列表大小)
- 按家庭
- 家庭
- 条目
- 家庭
- 按字母顺序
通用名称
- 信件(减少整体列表大小)
- 条目
- 信件(减少整体列表大小)
注意:所有条目都有注释 注2:字母是用于排序的字母表中的字母,
例如:
- a
- 苹果
- b
- 巴士
主类:
Public Class MainSystem
Public herbs As New Dictionary(Of Integer, herbEntry)
Public glossary As New Dictionary(Of Integer, glossaryEntry)
End Class
GlossaryEntry:
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
HerbEntry:
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 的链接,我已经得到了显示我的对象的树。但是,目前这棵树看起来像这样:
- Herbs
- 通用名称
- 条目中的 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>
Im making a herbal database program and I am having troubles setting up HierarchicalDataTemplates for my main data class.
Tree layout wanted:
- Glossary
- Category1
- Letter (Reduces overall list size)
- Entry
- Note1
- Note2
- Entry
- Letter (Reduces overall list size)
- Category1
Herbs
Botanical Name
- Alphabetical
- Letter (Reduces overall list size)
- Entry
- Letter (Reduces overall list size)
- By Family
- Family
- Entry
- Family
- Alphabetical
Common Name
- Letter (Reduces overall list size)
- Entry
- Letter (Reduces overall list size)
NOTE: All entries have notes
NOTE2: Letter is a letter of the alphabet for sorting
Ex:
- a
- apple
- b
- bus
Main Class:
Public Class MainSystem
Public herbs As New Dictionary(Of Integer, herbEntry)
Public glossary As New Dictionary(Of Integer, glossaryEntry)
End Class
GlossaryEntry:
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
HerbEntry:
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
EDIT: Thanks to the link from @AngelWPF I have got the tree displaying my object. But, currently the tree looks like this:
- Herbs
- Common Name
- CommonName item from entry
- Another CommonName item from entry
- Common Name
- CommonName item from entry
- Another CommonName item from entry
- Common Name
How can I make this change to match my hierarchy?
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此示例可以指导您为每种类型的绑定项目分配不同级别的不同项目模板...
在 TreeView 中拥有分层数据模板
This example may guide you to assign different item templates at different levels for each type of bound item ...
Having HierarchicalDataTemplates in a TreeView