I am trying to use link to group data and use it directly in treeview1.itemsource. The
code I used is:
DisksTreeView1.ItemsSource = (From g As Classes.DiskPrime In CurrentVariables.DisksList
Group By g.Genre
Into MyGroup = Group)
and Xaml is:
<TreeView Name="DisksTreeView1" >
<TreeView.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Namee}" />
</DataTemplate>
</TreeView.ItemTemplate>
</TreeView>
The class code is:
Public Class DiskPrime
Property ID As String
Property Namee As String
Property Genre As String
Property DateCreated As Date
Property Path As String
End Class
After running the program I am only getting a blank treeview, could you please correct me where i have done wrong. Thank you.
Using
GroupByreturns anIEnumerable<IGrouping<string, DiskPrime>>, which means you are actually binding to anIGrouping<string, DiskPrime>and not to aDiskPrime.To see the group names you could bind to
Keyrather thanNameeThis will only display the first level though (the group names). In order to see which elements each group contains, you’ll need to use
HierarchicalDataTemplateinstead ofDataTemplate.