SevenDays
SevenDays

Reputation: 3768

Scroll to bottom of listbox wp7

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();

Upvotes: 1

Views: 2131

Answers (2)

Ernest Poletaev
Ernest Poletaev

Reputation: 590

Call UpdateLayout before ScrollIntoView

var item = listmy.Items[listmy.Items.Count - 1];
listmy.UpdateLayout();
listmy.ScrollIntoView(item);
listmy.UpdateLayout();

Upvotes: 3

Jeff Ogata
Jeff Ogata

Reputation: 57783

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);
} 

Upvotes: 4

Related Questions