在使用LINQ的DataGrid
中,排序和滚动非常慢。将它与存储过程的结果绑定时,它的效果很好。
只有200条记录。这是为什么?
我尝试使用以下属性来DataGrid
,但没有运气:
EnableRowVirtualization="True"
EnableColumnVirtualization="True"
ScrollViewer.CanContentScroll="True"
这是简单的LINQ代码,它返回带有客户对象的客户列表:
public List<Customer> GetLinkedCustomer()
{
using (MYModel context = new MYModel())
{
return context.Customers.Where(x => x.CustLong1 != null).OrderBy(customer => customer.LastName).ToList();
}
}
XAML代码:
<Grid Margin="5,5,5,5" Height="Auto" Width="700">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<DataGrid Grid.Row="0" Name="dgLinkedCustomers" Height="250" CanUserAddRows="False" AutoGenerateColumns="False" CanUserSortColumns="True" IsReadOnly ="True" SelectionMode="Single">
<DataGrid.Columns>
<DataGridTextColumn IsReadOnly="True" Binding="{Binding FirstName , IsAsync=True}" Header="{x:Static res:Strings.Common_FirstName}" Width="150"/>
<DataGridTextColumn IsReadOnly="True" Binding="{Binding LastName , IsAsync=True}" Header="{x:Static res:Strings.Common_LastName}" Width="175"/>
<DataGridTextColumn IsReadOnly="True" Binding="{Binding ShopName, IsAsync=True}" Header="{x:Static res:Strings.ShopName}" Width="215"/>
<DataGridTextColumn IsReadOnly="True" Binding="{Binding CustLong1 , IsAsync=True}" Header="{x:Static res:Strings.AccountNumber}" Width="*"/>
</DataGrid.Columns>
</DataGrid>
<StackPanel Grid.Row="1" Orientation="Vertical" Margin="0,0,0,5" HorizontalAlignment="Right">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<Button Name="Close" Margin="0,0,10,0" Width="100">
<AccessText Text="{x:Static res:Strings.BtnText_Close}" />
</Button>
<Button Name="Unlink" Margin="0,0,10,0" Width="100" Click="Unlink_OnClick">
<AccessText>Unlink</AccessText>
</Button>
</StackPanel>
</StackPanel>
</Grid>