为什么 WPFToolkit DataGrid 绑定时如此慢?
我有一个非常简单的测试应用程序,其中有两个对象,每个对象都有一个小的项目集合。当我选择一个对象时,我会在 WPFToolkit DataGrid 中显示其集合。
问题是存在明显的延迟,因此如果您按向上/向下键在对象之间切换选择,您会发现它无法跟上。
为什么表现这么差?
<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>
DataContext 填充了一些测试类,其中填充了 50 项随机测试数据。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将属性
AutoGenerateColumns="True"
更改为AutoGenerateColumns="False"
并定义数据网格的列:这为我解决了性能问题。
Change the attribute
AutoGenerateColumns="True"
toAutoGenerateColumns="False"
and define your columns for the datagrid:This is what fixed the performance issues for me.