简体   繁体   English

滚动到列表框wp7的底部

[英]Scroll to bottom of listbox wp7

I have a listbox with more than 20 items.我有一个包含 20 多个项目的列表框。 How I can scroll to bottom of it?我如何滚动到它的底部? I tried the ScrollIntoView method, but no success:我尝试了ScrollIntoView方法,但没有成功:

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. ScrollIntoView方法需要一个 object(要滚动到的项目),但您传入的是所选项目的数字索引。 This will work:这将起作用:

void MainPage_Loaded(object sender, RoutedEventArgs e)
{
    listmy.SelectedIndex = listmy.Items.Count - 1;
    listmy.ScrollIntoView(listmy.SelectedItem);
} 

Call UpdateLayout before ScrollIntoView在 ScrollIntoView 之前调用 UpdateLayout

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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