开发者

Why is WPFToolkit DataGrid so slow when binding?

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="开发者_如何学Chttp://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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜