1

I have a listbox with more than 20 items. How I can scroll to bottom of it? I tried the ScrollIntoView method, but no success:

listmy.SelectedIndex = listmy.Items.Count;// listmy.Items.Count - 1;
            listmy.ScrollIntoView(listmy.SelectedIndex);
            listmy.UpdateLayout();
Michael Donohue
  • 11,776
  • 5
  • 31
  • 44
SevenDays
  • 3,718
  • 10
  • 44
  • 71

2 Answers2

4

The ScrollIntoView method expects an object (the item to scroll to), but you are passing in the numeric index of the selected item. This will work:

void MainPage_Loaded(object sender, RoutedEventArgs e)
{
    listmy.SelectedIndex = listmy.Items.Count - 1;
    listmy.ScrollIntoView(listmy.SelectedItem);
} 
Jeff Ogata
  • 56,645
  • 19
  • 114
  • 127
3

Call UpdateLayout before ScrollIntoView

var item = listmy.Items[listmy.Items.Count - 1];
listmy.UpdateLayout();
listmy.ScrollIntoView(item);
listmy.UpdateLayout();
Ernest Poletaev
  • 558
  • 5
  • 15
  • This method is not working properly. Imagein you use ObservableCollectioin as an Item Source. It works fine until you enter the same string as previous. In this case you will be positioned on your first value of string... – alerya Apr 03 '12 at 19:02