为什么我当前添加的listbox项目是不可访问的?

时间:2022-05-01 14:14:39

I have a listbox named as EntrylistBox. I am adding items in it and now i want to access ui container of last added items but its giving null. While i can access

我有一个名为EntrylistBox的列表框。我在其中添加项目,现在我想访问上次添加的项目的ui容器,但它的值为null。虽然我可以访问

EntrylistBox.Items.Count - 2

EntrylistBox.Items。数- 2

index but last index is returning null , now I'm wondering why? Any help

但最后一个索引返回null,现在我想知道为什么?任何帮助

I'm using following code to access ui container of last added item in listbox:

我使用以下代码访问列表框中最后添加项的ui容器:

 EntrylistBox.Items.Add(entry);
 var container= EntrylistBox.ItemContainerGenerator.ContainerFromItem(EntrylistBox.Items[EntrylistBox.Items.Count - 1]) as FrameworkElement;

1 个解决方案

#1


0  

ItemContainer will only created for the items which are all in the view due to virtualization. So you can't able to get the ItemContainer if the item is not in view.

由于虚拟化,ItemContainer将仅为视图中所有的项创建。因此,如果项目不在视图中,则无法获得ItemContainer。

Regards, Riyaj Ahamed I

问候,艾哈迈德Riyaj我

#1


0  

ItemContainer will only created for the items which are all in the view due to virtualization. So you can't able to get the ItemContainer if the item is not in view.

由于虚拟化,ItemContainer将仅为视图中所有的项创建。因此,如果项目不在视图中,则无法获得ItemContainer。

Regards, Riyaj Ahamed I

问候,艾哈迈德Riyaj我