我有一个启动对话框按钮,它创建一个窗口的视图模型并将其绑定到窗口(它启用了UI虚拟化).第一次单击启动对话框只需1秒钟.但是如果我经常或背靠背打开相同的对话框,它会花费更多的时间来填充网格数据源以进行下一次迭代.如果我暂停一下,然后再打开窗口,那么只需要大约1或2秒钟.
for first time populating the item source it take only 1 second:
next time populating the item source it takes 2 second
next time populating the item source it takes 3 second
next time populating the item source it takes 6 second
next time populating the item source it takes 8 second
Run Code Online (Sandbox Code Playgroud)
但是,如果我调用不推荐的GC.Collect(),那么填充网格数据源总是需要大约1秒钟.但呼唤
Gc.Collect()
Gc.WaitForPendingFinalizer()
Gc.Collect()
Run Code Online (Sandbox Code Playgroud)
每次迭代花费我一些时间.
我知道打电话GC.Collect不是一个好选择.任何人都可以建议我如何提高我的应用程序性能.
我更关心用户机器,因为我的机器具有非常好的配置,而用户机器可能不那么快.
WPF中是否有PagedCollectionView的实现?它存在于Silverlight中但不在WPF中.
如果没有,实现这个最简单的方法是什么?
我正在使用这里提供的示例StackOverflow相关的问题,如果我在网格中有偶数个项目然后它的工作都很好,但是如果我有一个像7个项目的奇数,它会抛出超出范围的异常我通过添加此行修复
public override object GetItemAt(int index)
{
var offset = ((index % (this._itemsPerPage)) + this.StartIndex) > this._innerList.Count - 1 ? 0 : index % (this._itemsPerPage);
return this._innerList[this.StartIndex + offset];
}
Run Code Online (Sandbox Code Playgroud)
问题是,在修复此问题后,如果您将每页的项目设置为2,那么您将有4页,前3页看起来正确,但最后一页重复最后一项两次.像这样

我是WPF的新手,我不知道如何处理这件作品,我不明白为什么会重复这个项目.
在我的应用程序中,我想从 WCF 服务(作为 Windows 服务托管)返回一组对象,以填充 WPF 应用程序中的 DataGrid。集合中的对象数量从一到几百不等,具体取决于调用的方法。
我很好奇处理从服务返回大型集合的“最佳”方法是什么。
这些是我看到的建议选项:
yield关键字做一些事情,但这超出了我的头脑,我无法遵循它。:-/完成这项任务的最佳方法是什么,为什么?