开发者

Scroll to bottom of listbox wp7

开发者 https://www.devze.com 2023-03-19 18:59 出处:网络
I have a listbox with more than 20 items. How I can scroll to bottom of it? I tried the Scroll开发者_开发技巧IntoView method, but no success:

I have a listbox with more than 20 items. How I can scroll to bottom of it? I tried the Scroll开发者_开发技巧IntoView 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();
0

精彩评论

暂无评论...
验证码 换一张
取 消