【发布时间】:2014-04-20 02:38:38
【问题描述】:
我有一个 DataGrid,我使用 ICollectionView 对大型集合中的项目进行分组,在某些情况下超过 20k 行。我之前使用过这种方法,在显示所有行或虚拟化以创建响应速度更快的页面方面取得了不同程度的成功。在这种情况下,我想尽可能地进行虚拟化以保持 UI 响应。我已使用此答案中的提示,但对我的问题收效甚微。 Helpful DataGrid Link
我的主要问题是在将数据加载到 ICollectionView 视图/源时,DataGrid 出现了几秒钟的延迟,我希望通过适当的虚拟化将其最小化。这是我的一些代码:
<DataGrid Margin="0,2,0,0" IsReadOnly="True" ItemsSource="{Binding DataView,IsAsync =True}" EnableRowVirtualization ="True" MaxWidth="2560" MaxHeight="1600"
Grid.Row="2" SelectionMode="Extended" VirtualizingPanel.IsVirtualizingWhenGrouping="True" SelectionUnit="FullRow" SelectedItem="{Binding SelectedOutage}">
<DataGrid.GroupStyle>
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Margin" Value="0,0,0,5"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<Expander IsExpanded="True" Foreground="{StaticResource Foreground}" Background="{StaticResource AlternatingBackground}">
<Expander.Header>
<TextBlock Text="{Binding Name}" Margin="5,0,0,0" Width="300"/>
</Expander.Header>
<ItemsPresenter />
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</DataGrid.GroupStyle>
<!--Follows are DataGrid.ContextMenu and DataGridTextColumns with fixed widths-->
</DataGrid>
还有 c# 项:
public ICollectionView DataView { get; set; }
private readonly ObservableCollection<EquipmentMonitorRow> equipment = new ObservableCollection<EquipmentMonitorRow>();
DataView = CollectionViewSource.GetDefaultView(equipment);
DataView.GroupDescriptions.Add(new PropertyGroupDescription("GroupName"));
equipment.Clear();
//Lag is during this item adding.
equipment.AddRange(data);
所以希望我错过了一些虚拟化,或者我可以添加不同的项目或其他东西。 任何帮助,将不胜感激。谢谢。
【问题讨论】:
标签: c# wpf xaml datagrid grouping