For example try this trivial WPF window:
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBox Grid.Row="0" Text="{Binding Path=Filter, UpdateSourceTrigger=PropertyChanged}" />
<DataGrid Grid.Row="1" ItemsSource="{Binding FilteredList}">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding}" />
</DataGrid.Columns>
</DataGrid>
</Grid>
</Window>
with this code behind:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows;
public partial class MainWindow : Window, INotifyPropertyChanged
{
List<string> items = new List<string>();
string filter = string.Empty;
public MainWindow()
{
InitializeComponent();
DataContext = this;
for (int i = 0; i < 100; i++) items.Add(i.ToString());
}
public IEnumerable<string> FilteredList
{
get { return this.items.Where(item => item.Contains(filter)).ToArray(); }
}
public string Filter
{
get { return filter; }
set
{
if (filter != value)
{
filter = value;
PropertyChanged(this, new PropertyChangedEventArgs("FilteredList"));
}
}
}
public event PropertyChangedEventHandler PropertyChanged = (s, e) => { };
}
There are only one hundred strings in the grid. The textbox allows filtering the strings.
But writing for example 123
into the filter and then deleting it again freezes the application for multiple seconds. Why is this not instant?
Edit: In .NET 4.5 it is indeed instant, even with 10'000 items. Seems to be a regression in .NET 4.6?
DataGrid.EnableColumnVirtualization
is False by default. Setting it to True helps.