代码之家  ›  专栏  ›  技术社区  ›  Geoff Appleford

Silverlight:ItemsControl中类似Datagrid的分组

  •  7
  • Geoff Appleford  · 技术社区  · 16 年前

    是否可以在Silverlight中对ItemsControl或Listbox中的项目进行分组?这些控件绑定到DomainDataSource。

    或者是否有任何第三方控件可以执行此操作?

    这就是我正在尝试创建的UI类型。

    alt text

    4 回复  |  直到 9 年前
        1
  •  5
  •   Geoff Appleford    15 年前

    可以通过使用嵌套 ItemsControls PagedCollectionView .

    假设我有一个数据源- MyItems Category , Section Option PagedCollectionView IEnumerable(of MyItems) 并告诉它根据哪些字段进行分组。

    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

    hisMyItems.ItemsSource = pcv.Groups
    

    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>
    

        2
  •  0
  •   Stephen Price    16 年前

    DataGrid控件支持分组。

    Tim Heuer有一个关于使用datagrid分组的好博客。 link text

        3
  •  0
  •   AnthonyWJones    16 年前

    Toolkit

    参见手风琴式行为示例 here .