WPF滚动视图默认滚动到底部
我有一个包含 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您有权访问
ScrollViewer
,您还可以使用ScrollViewer.ScrollToBottom()
方法。If you have access to the
ScrollViewer
, you could also use theScrollViewer.ScrollToBottom()
method.是的,有一个简单的方法。
这将滚动到第一项。您所需要做的就是找到您的最后一个项目。
Yes, there is a easy way.
This will scroll to the first item. All you need to do is to find your last item.
另外,如果 ScrollToBottom 方法没有一直到达底部(仅停止 1 项),请在调用
ScrollViewer.ScrollToBottom
ScrollViewer.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 toScrollViewer.ScrollToBottom
.它非常简单并且有效:
我知道这不是最优雅的解决方案,但至少对于字符串对象来说效果很好。
it's very easy and works:
I know this isn't the most elegant solution but at least for string object works very well.