【问题标题】:WPF Datagrid, is it possible to have a mixture of Groups and plain (non grouped) rows?WPF Datagrid,是否可以混合使用组和普通(非分组)行?
【发布时间】:2012-03-01 21:50:06
【问题描述】:

我正在使用 WPF Datagrid 并且需要显示 10,000 行,因此需要虚拟化。从 StackOverflow 上的几篇文章中,我看到 WPF Datagrid 无法实现虚拟化 + 分组。这是因为无法虚拟化渲染组的 Expander 模板。

在我们的系统中,我们可能有 10,000 行,但每组中只有 3 或 4 行。此外,绝大多数行没有分组——它们的 GroupId 为空。在原型中,我正在将这些渲染作为没有标题的组扩展器。我最喜欢的是那些不分组的,只是行,其余的在扩展器中呈现。这可能吗?

【问题讨论】:

    标签: wpf datagrid virtualization


    【解决方案1】:

    试试这个...

    <GroupStyle.ContainerStyle>
        <Style TargetType="{x:Type GroupItem}">
            <Style.Resources>
                <ControlTemplate x:Key="MultiItemGroupTemplate"
                                 TargetType="{x:Type GroupItem}">
                    <Expander IsExpanded="False">
                        <Expander.Header>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="{Binding Path=Name}" />
                            </StackPanel>
                        </Expander.Header>
                        <ItemsPresenter />
                    </Expander>
                </ControlTemplate>
                <ControlTemplate x:Key="SingleItemGroupTemplate"
                                 TargetType="{x:Type GroupItem}">
                       <ItemsPresenter />
                </ControlTemplate>
            </Style.Resources>                                
            <Style.Triggers>
                <DataTrigger Binding="{Binding ItemCount}" Value="1">
                    <Setter Property="Template"
                            Value="{StaticResource SingleItemGroupTemplate}">
                    </Setter>
                </DataTrigger>
            </Style.Triggers>
            <Setter Property="Template"
                    Value="{StaticResource MultiItemGroupTemplate}"/>
        </Style>
    </GroupStyle.ContainerStyle>
    

    注意:请注意,DataGrid 会发生变化...DataGrid 的ItemPresenter 实际上是DataGridRowsPresenter

    【讨论】:

      猜你喜欢
      • 2017-06-30
      • 2011-03-16
      • 1970-01-01
      • 2013-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-17
      • 2013-04-09
      相关资源
      最近更新 更多