为什么ListView.ScrollIntoView无法正常工作? [英] Why doesn't ListView.ScrollIntoView ever work?

查看:201
本文介绍了为什么ListView.ScrollIntoView无法正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图滚动到视图中,以便始终显示垂直listivew中的最后一项,但ListView.ScrollIntoView()永远不起作用。

I am trying to scroll into view so that the very last item in a vertical listivew is always showing, but ListView.ScrollIntoView() never works.

我有尝试过的:

button1_Click(object sender, EventArgs e)
{

            activities.Add(new Activities()
            {
                Time = DateTime.Now,
                Message = message
            });

            ActivityList.ItemsSource = activities;

            // Go to bottom of ListView.
            ActivityList.SelectedIndex = ActivityList.Items.Count;
            ActivityList.ScrollIntoView(ActivityList.SelectedIndex);
}

我也尝试过:

ActivityList.ScrollIntoView(ActivityList.Items.Count) ActivityList.ScrollIntoView(ActivityList.Items.Count + 1); code>,但没有任何作用。

ActivityList.ScrollIntoView(ActivityList.Items.Count), and ActivityList.ScrollIntoView(ActivityList.Items.Count + 1); but nothing is working.

请帮助。真烦人。而且文档不是很有帮助。

Please help. This is really annoying. And the documentation isn't very helpful in this case.

推荐答案

您在方法需要项目对象时传递索引。尝试滚动到所选项目。

You're passing in the index when the method expects the item object. Try this to scroll to the selected item.

ActivityList.ScrollIntoView(ActivityList.SelectedItem);

如果要滚动到最后一个项目,可以使用此

If you want to scroll to the last item, you can use this

ActivityList.ScrollIntoView(ActivityList.Items[ActivityList.Items.Count - 1]);

这篇关于为什么ListView.ScrollIntoView无法正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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