在datagrid中显示数千行,加载行时需要光标等待 [英] Showing thousands of rows in datagrid, need cursor to wait while loading rows

查看:65
本文介绍了在datagrid中显示数千行,加载行时需要光标等待的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用C#动态创建DataGrid列并将数据同时加载到列表中.游标正在同时等待.现在,在创建列并将数据加载到列表之后.我设置myDataGrid.Itemssouce = mylist; Cursor = Curosrs.Arrow;

I´m creating DataGrid columns dynamicly in C# and loading data into a list at the same time. Cursor is waiting at the same time. Now, after columns are created and data is loaded into a list. I set the myDataGrid.Itemssouce = mylist; Cursor=Curosrs.Arrow;

然后,如您所见,我再次将Cursor设置为箭头.但是,当列表包含数千行时,数据网格显示这些行大约需要5到10秒.可以,但是我需要光标处于等待阶段,虽然没有显示数据,但是 光标不在等待中,其箭头.有任何建议吗?

Andafter that, I set the Cursor to arrow again as you can see. But when the list contains thousands of rows it takes about 5-10 seconds for the datagrid to show the rows. Its ok but I need the cursor to be in waiting stage allso while data is not shown but the cursor is not waiting, its arrow. Any suggestions, please?

推荐答案

嗨GaiusBaltar,

Hi GaiusBaltar,

在DataGrid加载并显示项目的5-10秒内,UI线程正忙,因此UI上的任何更改都不会立即生效.我们需要等到项目加载完毕.因此,如果要将光标"更改为等待",可以将其更改 在设置ItemsSource属性之前.

由于项源包含数千行,并且DataGrid显示行大约需要5-10秒,因此可以将DataGrid的Height属性设置为固定值,并将ScrollViewer.VerticalScrollBarVisibility设置为Auto(默认) EnableRowVirtualization的值将为true.因此,DataGrid将仅加载项目目前在DataGrid中可见的UI,它将具有良好的性能.

During the 5-10 seconds which DataGrid load and show the items, the UI thread is busy, so that any change on the UI will not take into effect immediately. We need to wait until items loaded. So if you want to change the Cursor to Wait, you can change it before setting the ItemsSource property.

Since the items source contains thousands of rows, and it take about 5-10 seconds for the DataGrid to show the rows, you can set the Height property of the DataGrid with a fixed value, and set the ScrollViewer.VerticalScrollBarVisibility as Auto, the default value of the EnableRowVirtualization will be true. So the DataGrid will only load the items’ UI which are currently visible in the DataGrid, it will have a good performance.

希望这会有所帮助.

最诚挚的问候,
潘凯文

Best regards,
Kevin Pan


这篇关于在datagrid中显示数千行,加载行时需要光标等待的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆