ListBox.ScrollIntoView() 在 WP7 中似乎不起作用 [英] ListBox.ScrollIntoView() does not seem to work in WP7

查看:28
本文介绍了ListBox.ScrollIntoView() 在 WP7 中似乎不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当向 itemssource 添加新项目时,我都想将列表框滚动条移动到底部,但是 ScrollIntoView() 如果我将它传递给新添加的项目,或它的索引.有没有人让它起作用,或者对我如何将列表框向下滚动到底部有任何其他建议?

I want to move the listbox scrollbar to the bottom whenever a new item is added to the itemssource, but ScrollIntoView() doesn't seem to do anything if I pass it either a reference to the newly added item, or the index of it. Has anyone gotten this to work, or have any other suggestions as to how I could scroll the listbox down to the bottom?

一些代码:

    void Actions_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
    {
        //if a new item was added, set it to the selected item
        if (e.NewItems != null)
        {
            MainListBox.SelectedIndex = e.NewStartingIndex;

            //MainListBox.ScrollIntoView(MainListBox.Items.Last());     //todo: this doesnt seem to work
        }
    }

推荐答案

MSDN 说:

当 ItemsSource 集合的内容发生变化时,尤其是在集合中添加或删除了许多项时,您可能需要在调用 ScrollIntoView 之前调用 UpdateLayout(),以便指定项滚动到视口中.

When the contents of the ItemsSource collection changes, particularly if many items are added to or removed from the collection, you may need to call UpdateLayout() prior to calling ScrollIntoView for the specified item to scroll into the viewport.

这可能是你的问题吗?

这篇关于ListBox.ScrollIntoView() 在 WP7 中似乎不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆