简体   繁体   中英

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

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

Call UpdateLayout before ScrollIntoView

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM