停止自动滚动到列表框底部
我在 UserControl 中使用 Telerik 的 RadGridView 来显示从 XMPP 服务器收到的消息列表。我已经能够设置它,以便当我收到消息时,我可以滚动到列表底部,如下所示:
private GridViewScrollViewer scrollViewer;
void controller_OnMessageReceived(object sender, EventArgs e)
{
scrollViewer = receivedMessageList.ChildrenOfType<GridViewScrollViewer>().FirstOrDefault();
scrollViewer.ScrollToBottom();
}
但是,我想要做的是当用户使用滚动条时禁用自动滚动,并且然后当他滚动到列表底部时重新启用它。我以为我可以附加到 ScrollChanged
事件,但这似乎没有提供足够的信息供我使用。
作为对控件的 Loaded
事件的一个轻微补充,我上面的 RadGridView 的scrollViewer 调用为 null。我认为一旦控件被加载,所有 UI 元素就都准备好了?
I am using Telerik's RadGridView within a UserControl to display a list of messages received from an XMPP server. I have been able to set it so that when I receive a message I can scroll to the bottom of the list with something like this:
private GridViewScrollViewer scrollViewer;
void controller_OnMessageReceived(object sender, EventArgs e)
{
scrollViewer = receivedMessageList.ChildrenOfType<GridViewScrollViewer>().FirstOrDefault();
scrollViewer.ScrollToBottom();
}
However what I want to be able to do is disable the auto scrolling when the user uses the scroll bar and then re-enable it when he scrolls to the bottom of the list. I thought I could attach to the ScrollChanged
event but that doesn't seem to hold enough information for me to use.
As a slight addition to this in the Loaded
event of the control, and the RadGridView the scrollViewer call I have above comes as null. I thought that once the control was Loaded that all UI elements are ready?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
关于空scrollViewer变量,我想当您加载控件时,不会显示scrollViewer,因为其中还没有任何内容。尝试设置:
在 XAML
Now 中解决实际问题:
您可以监视滚动查看器的
HorizontalOffset
和VerticalOffset
:在类中创建两个
Double
字段来存储它们,然后在调用之前>ScrollToBottom()
,将当前值与保存的值进行比较。如果用户手动移动滚动条,则值将不同并且您不会滚动,否则您将使用
ScrollToBottom()
。About the null scrollViewer variable, I guess when you load the control, the scrollViewer is not shown since there is nothing in it yet. Try setting:
In your XAML
Now for the actual problem:
You could monitor the
HorizontalOffset
and theVerticalOffset
of the scrollviewer:Create two
Double
fields in your class to store them and then, before callingScrollToBottom()
, compare the current values to the ones saved.If the user manually moved the scrollbars, the values will be different and you don't scroll, otherwise you
ScrollToBottom()
.