How to know if a displayed listboxItem is in a WPF ListBox

203 Views Asked by At

How do I know if the rendered listboxItem is in a WPF ListBox? I want to get the list box items that are displayed in the screen, because I want to move the item at the bottom to the top of the screen like when auto-scrolling.

I already searched Google, but couldn't find an answer, and I used a method like below but it didn't work on rendered items:

MyViewModel myViewModel = LbList.Items.getItemAt(0);
LbChatList.ScrollIntoView(myViewModel);
1

There are 1 best solutions below

2
charles kim On BEST ANSWER

In "Scroll ListViewItem to be at the top of a ListView" someone used the listView but I used a listbox instead.

I can get the ScrollViewer more easily using:

ScrollViewer myScrollviwer = FindVisualChild<ScrollViewer>(myListBoxObject);