WPF滚动视图默认滚动到底部

发布于 2024-08-30 19:13:48 字数 165 浏览 2 评论 0原文

我有一个包含 ListBox 的 ScrollViewer。我希望 ScrollViewer 在视图加载后默认一直滚动到底部!这是因为最新的元素始终是 ListBox 中的最后一个元素。

有没有一种简单的方法可以实现这种行为?

谢谢

I have a ScrollViewer containing a ListBox. I would like the ScrollViewer to scroll all the way to the bottom by default when the view has been loaded! This because the most recent element is always the last element in the ListBox.

Is there an easy way to achieve this behavior?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

雨落□心尘 2024-09-06 19:13:48

如果您有权访问 ScrollViewer,您还可以使用 ScrollViewer.ScrollToBottom() 方法。

If you have access to the ScrollViewer, you could also use the ScrollViewer.ScrollToBottom() method.

∞觅青森が 2024-09-06 19:13:48

是的,有一个简单的方法。

lv.ScrollIntoView(lv.Items[0]);

这将滚动到第一项。您所需要做的就是找到您的最后一个项目。

Yes, there is a easy way.

lv.ScrollIntoView(lv.Items[0]);

This will scroll to the first item. All you need to do is to find your last item.

任谁 2024-09-06 19:13:48

另外,如果 ScrollToBottom 方法没有一直到达底部(仅停止 1 项),请在调用 ScrollViewer.ScrollToBottomScrollViewer.UpdateLayout() 方法>。

Also, if the ScrollToBottom method doesnt go all the way to the bottom (stops 1 item short), call the ScrollViewer.UpdateLayout() method just before your call to ScrollViewer.ScrollToBottom.

吻泪 2024-09-06 19:13:48

它非常简单并且有效:

myListBox.ScrollIntoView(lastObjectAdded);

我知道这不是最优雅的解决方案,但至少对于字符串对象来说效果很好。

it's very easy and works:

myListBox.ScrollIntoView(lastObjectAdded);

I know this isn't the most elegant solution but at least for string object works very well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文