WPF ListBox Scroll to end automatically

niao picture niao · Feb 25, 2010 · Viewed 55.6k times · Source

In my application, I have a ListBox with items. The application is written in WPF.

How can I scroll automatically to the last added item? I want the ScrollViewer to be moved to the end of the list when new item has been added.

Is there any event like ItemsChanged? (I don't want to use the SelectionChanged event)

Answer

Oz Mayt picture Oz Mayt · Jun 5, 2013

Try this:

lstBox.SelectedIndex = lstBox.Items.Count -1;
lstBox.ScrollIntoView(lstBox.SelectedItem) ;

In your MainWindow, this will select and focus on last item on the list!