Scroll to bottom of listbox wp7

ⅰ亾dé卋堺 提交于 2020-01-06 03:06:26

问题


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

回答1:


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



回答2:


Call UpdateLayout before ScrollIntoView

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


来源:https://stackoverflow.com/questions/6657923/scroll-to-bottom-of-listbox-wp7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!