Question

I have a big list (~10000 items) inside a ComboBox, that uses the VirtualizingStackPanel class. The scrolling performance is good, anyway I like to know how to identify the top item shown in the GUI - which is, not necessarily the one with index zero, but the one that is on top of the current scrolled item list. ? Thank you.

Était-ce utile?

La solution

I use the FrameworkElement.IsVisible property. Using the method at the link below, you can also check to see if an element is partially visible(which would be useful in your case):

In WPF, how can I determine whether a control is visible to the user?

You could (by using a background thread or by doing a computation when the user scrolls in the combobox), check the items in the ComboBox to see if their FrameworkElement.IsVisible property were set to true. If so, you update that elements IsVisible property in its ViewModel. Now you have a collection in your ViewModel of items that are marked visible or not(and that are constantly updated concerning the visibility of the CoboBox item that it represents). Now you can find which is the first using .First(x=>x.IsVisible==true) on the collection of items.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top