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>