我正在尝试使用link来分组数据,并在treeview1.itemsource中直接使用它。我使用的代码是:
DisksTreeView1.ItemsSource = (From g As Classes.DiskPrime In CurrentVariables.DisksList
Group By g.Genre
Into MyGroup = Group)而Xaml是:
<TreeView Name="DisksTreeView1" >
<TreeView.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Namee}" />
</DataTemplate>
</TreeView.ItemTemplate>
</TreeView>类代码为:
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在运行程序后,我只得到一个空白的树视图,你能纠正我哪里做错了吗?谢谢。
发布于 2012-08-04 00:59:49
使用GroupBy会返回一个IEnumerable<IGrouping<string, DiskPrime>>,这意味着您实际上绑定到了IGrouping<string, DiskPrime>,而不是DiskPrime。
要查看组名,可以绑定到Key而不是Namee
这将只显示第一级(组名)。为了查看每个组包含哪些元素,您需要使用HierarchicalDataTemplate而不是DataTemplate。
https://stackoverflow.com/questions/11799615
复制相似问题