且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么 ItemContainerGenerator.ContainerFromIndex() 返回 null 以及如何避免这种行为?

更新时间:2023-02-25 21:15:48

DataGrid 正在虚拟化项目,相应的行(即容器)仅在该行在视图中时创建.

The DataGrid is virtualizing the items, the respective rows (i.e. containers) are only created when the row is in view.

>

您可以关闭虚拟化(如果您有很多项目,这会使第一次加载非常慢,而且内存使用量也会更高)或者您只是遍历数据并检查应该绑定到数据的数据对象的属性值-网格.通常你根本不需要 UI 元素...

You could either turn off virtualization (which makes the first time loading very slow if you have many items, also the memory usage will be higher) or you just iterate over the data and check the values of the data objects' properties which should be bound to the data-grid. Usually you should not need the UI elements at all...