2

I have a very simple test application where I have two objects, each with a small collection of items. when I select an object I display its collection in a WPFToolkit DataGrid.

The problem is there is a noticeable delay, such that if you press up/down keys to toggle selection between objects you can see it can't keep up.

Why is the performance so bad?

<Window x:Class="SlowGridBinding.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:Controls="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit"
    Title="MainWindow" Height="350" Width="525">
<StackPanel>
    <ListBox ItemsSource="{Binding Shops}" DisplayMemberPath="Name" IsSynchronizedWithCurrentItem="True"/>
    <Controls:DataGrid ItemsSource="{Binding Shops/Vegetables}" AutoGenerateColumns="True"/>
</StackPanel>

The DataContext is populated with some test classes filled with 50 items of random test data.

Jack Ukleja
  • 13,061
  • 11
  • 72
  • 113
  • 1
    possible duplicate http://stackoverflow.com/questions/1069025/wpf-toolkit-datagrid-performance http://stackoverflow.com/questions/1704512/wpf-toolkit-datagrid-scrolling-performance-problems-why – jonny Mar 15 '10 at 08:51

1 Answers1

1

Change the attribute AutoGenerateColumns="True" to AutoGenerateColumns="False" and define your columns for the datagrid:

<my:DataGrid AutoGenerateColumns="False" ... >
    <my:DataGrid.Columns>
        <my:DataGridTextColumn Header="Col1" Width="*" Binding="{Binding Path=Col1}" />
        <my:DataGridTextColumn Header="Col2" Width="*" Binding="{Binding Path=Col2}" />
        .
        .
        .
    </my:DataGrid.Columns>
</my:DataGrid>

This is what fixed the performance issues for me.

pi2
  • 21
  • 1