我正在制作一个草药数据库程序,我在为主数据类设置HierarchicalDataTemplates时遇到了麻烦。
想要树形布局:
草药
植物学名称
通用名称
注意:所有条目都有注释 注2:Letter是用于排序的字母表中的字母
例如:
主类:
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的链接,我得到了显示我的对象的树。但是,目前这棵树看起来像这样:
如何进行此更改以匹配我的层次结构?
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>
答案 0 :(得分:0)
此示例可能会指导您为每种类型的绑定项目分配不同级别的不同项目模板...