-2

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);
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
  • You can use the ListBox's ItemContainerGenerator to find the number of items in the viewport, and then you can iterate through those and check the visibility of the containers, but I don't think you're going to be able to produce the behaviour you are after with a standard ListBox. ScrollIntoView isn't going to give you that kind of behaviour. You need to write a custom control from scratch – Dean Chalk May 04 '20 at 06:23
  • @DeanChalk Thanks for your reply. i got two information about ListBox. – charles kim May 04 '20 at 08:37
  • Welcome to SO! When asking it's important to use clear language. If English isn't your primary language feel free to ask a peer to review your question and help clarify it. This helps avoid problems when we try to understand and/or correct it. See "[ask]" and the linked pages. – the Tin Man May 05 '20 at 05:10

1 Answers1

0

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);
the Tin Man
  • 158,662
  • 42
  • 215
  • 303