在Silverlight中,是否可以对ItemsControl或Listbox中的项目进行分组?这些控件绑定到DomainDataSource。
或者是否有第三方控件可以实现这一点?
更新:
我正在尝试创建这种类型的UI。
在Silverlight中,是否可以对ItemsControl或Listbox中的项目进行分组?这些控件绑定到DomainDataSource。
或者是否有第三方控件可以实现这一点?
更新:
我正在尝试创建这种类型的UI。
ItemsControls
绑定到PagedCollectionView来实现此操作。
假设我有一个数据源 - MyItems
- 其中包含字段:Category
,Section
和Option
。 我可以从IEnumerable(of MyItems)
创建一个PagedCollectionView
并告诉它按哪些字段进行分组。
Dim original As IEnumerable(Of MyItems) = GetMyItems()
Dim pcv = New PagedCollectionView(original)
pcv.GroupDescriptions.Add(New PropertyGroupDescription("Category"))
pcv.GroupDescriptions.Add(New PropertyGroupDescription("Section"))
ItemsControl
绑定到PagedCollectionView
。hisMyItems.ItemsSource = pcv.Groups
< p > PCV
创建了像这样的嵌套层次结构:
-Name
-Items
其中Name
是分组字段中的值,Items
包含该分组中的行/对象。如果您喜欢,也可以在xaml中创建PCV。
xaml代码如下:
<controls:HeaderedItemsControl x:Name="hisMyItems" Header="{Binding Name}" ItemsSource="{Binding Items}" >
<controls:HeaderedItemsControl.ItemTemplate>
<DataTemplate>
<controls:HeaderedItemsControl Header="{Binding Name}" ItemsSource="{Binding Items}" ItemsPanel="{StaticResource ItemsPanelTemplate1}" >
<controls:HeaderedItemsControl.ItemTemplate>
<DataTemplate>
<Button Content="{Binding Option}" />
</DataTemplate>
</controls:HeaderedItemsControl.ItemTemplate>
</controls:HeaderedItemsControl>
</DataTemplate>
</controls:HeaderedItemsControl.ItemTemplate>
</controls:HeaderedItemsControl>
我希望这样说起来更容易理解。我尝试从我的实际应用程序中简化了一些东西,但复制过程中可能出现了一些错误。当然,您也可以使用普通的ItemsControls或其他控件,并使用模板等进行自定义。
数据网格控件支持分组。
Tim Heuer在博客中介绍了如何使用数据网格进行分组。 链接文本