Is WPF ListBox equivalent to Windows Forms Listbox TopIndex?

Basically what I want to do is allow the user to enter a string value and display the list on the element that matches the entered text (or the first LIKE match).

If I use the .ScrollIntoView () method, the problem is that it puts the item at the bottom of the viewable area if the item is lower in the list than the current scroll position and it is at the top if it is larger in the list than the current scroll position ... I want to make it sequential by making it the top item in the list (unless, of course, that could be due to the fact that it is one of the last "pages" of items).

I tried to fake it by selecting an item that is further down the list, where x is the number of items visible. This works when going down, but breaks when returning. and I was unable to determine which index is currently at the top visible position in my list.

WinForms list boxes have a .TopIndex property that matches me exactly, but I couldn't find a WPF equivalent. Does anyone have an idea how to do this?

Thanks in advance!

0


source to share


1 answer


Use ScrollIntoView twice, first to show the very last item in the list, then to show the selected item. Thus, it will always work from the bottom up. You will need to call UpdateLayout after each call to make sure the positions are correct.



+2


source







All Articles