I am using .NET 4.0 WPF DataGrid bound to an ObservableCollection<T> . The collection contains rows added and deleted several times per second. DataGrid contained in TabControl / TabItem / Grid .
It works more or less OK, as long as I leave it visible. If I switch to another application tab, come back in a few minutes, the user interface stream will close within 30 seconds (about 1200 lines, about 40 of which are on the screen). All line data is already in memory, so there is no I / O. All related properties - either simple strings, numbers or dates, or the logic for creating them is very simple; nothing complicated or time consuming to calculate.
If the number of rows exceeds several hundred, selecting a new column for sorting is very slow. Adding a new line also seems slow. If I switch to another tab and then go back, the grid will reappear quickly.
Resizing the window is excellent.
Scrolling speed is slow at first, but after the grid is fully loaded; it is never wonderful. Without ScrollView.CanContentScroll="False" scrolling is so slow that it cannot be used. Using IsDeferredScrollingEnabled="True" instead causes a delay of 10+ seconds when rendering after the user releases the scroll bar - still an unacceptable user interface.
There are 17 DataGridTextColumns . Multiple columns use custom StringFormats , but nothing complicated. No TypeConverters .
Visual Studio tools / profiler were useless. This seems like a relatively simple / straightforward setup. Any suggestions on how to increase productivity would be appreciated.
I would also like to know WHY he is SO slow.
<DataGrid x:Name="MyGrid" AutoGenerateColumns="False" Margin="3,35,3,20" VerticalContentAlignment="Center" Width="Auto" FontSize="12" FontFamily="Consolas" ScrollViewer.CanContentScroll="False" CanUserResizeRows="False" AlternationCount="2" AlternatingRowBackground="#FFE3F0FF" VirtualizingStackPanel.VirtualizationMode="Recycling" IsReadOnly="True"> <DataGrid.Columns> <DataGridTextColumn Header="XX" Binding="{Binding Path=XX}" /> <DataGridTextColumn Header="YY" Binding="{Binding Path=YY, StringFormat={}{0:0.0}}"> <DataGridTextColumn.ElementStyle> <Style> <Setter Property="TextBlock.TextAlignment" Value="Right" /> </Style> </DataGridTextColumn.ElementStyle> </DataGridTextColumn> . . . </DataGrid.Columns> </DataGrid>