停止自动滚动到列表框底部

发布于 2024-12-11 03:21:35 字数 601 浏览 0 评论 0原文

我在 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 技术交流群。

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

发布评论

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

评论(1

ら栖息 2024-12-18 03:21:35

关于空scrollViewer变量,我想当您加载控件时,不会显示scrollViewer,因为其中还没有任何内容。尝试设置:

ScrollViewer.HorizontalScrollBarVisibility="Visible"
ScrollViewer.VerticalScrollBarVisibility="Visible"

在 XAML

Now 中解决实际问题:
您可以监视滚动查看器的 Horizo​​ntalOffsetVerticalOffset

在类中创建两个 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:

ScrollViewer.HorizontalScrollBarVisibility="Visible"
ScrollViewer.VerticalScrollBarVisibility="Visible"

In your XAML

Now for the actual problem:
You could monitor the HorizontalOffset and the VerticalOffset of the scrollviewer:

Create two Double fields in your class to store them and then, before calling ScrollToBottom(), 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().

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