ContextSwitchDeadlock
is usually an indication that the UI thread was busy for too long. Have you disabled the
VirtualStackPanel
by mistake or on purpose?
Here is a test with 100,000 items and it loads and runs almost instantly. Importantly, the
VirtualStackPanel
is active.
XAML
<Window
x:Class="VirtualListView.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
mc:Ignorable="d"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="Virtualized ListView" Height="300" Width="500">
<Grid>
<ListView ItemsSource="{Binding Persons}">
<ListView.View>
<GridView>
<GridViewColumn Header="Avatar" Width="100">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Image Source="{Binding AvatarUrl}" Margin="10" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Name" Width="200" DisplayMemberBinding="{Binding Name}" />
<GridViewColumn Header="Age" Width="50" DisplayMemberBinding="{Binding Age}" />
</GridView>
</ListView.View>
</ListView>
</Grid>
</Window>
Code Behind
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
DataContext = this;
Mock();
}
public ObservableCollection<Person> Persons { get; set; }
= new ObservableCollection<Person>();
private Random rand = new Random();
private void Mock()
{
for (int i = 0; i < 100000; i++)
{
Persons.Add(new Person
{
AvatarUrl = "http://www.freepngimg.com/download/happy_person/2-2-happy-person-free-download-png.png",
Name = $"Person {i}",
Age = rand.Next(20, 60)
});
}
}
}
public class Person
{
public string AvatarUrl { get; set; }
public string Name { get; set; }
public int Age { get; set; }
}