我可以在 UWP 中的多个 Listview 项目之间同步滚动吗? [英] Can I sync scrolling between multiple Listview items in UWP?

查看:23
本文介绍了我可以在 UWP 中的多个 Listview 项目之间同步滚动吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何链接 2 个 Listview 组件,使它们的滚动同步(当我滚动一个时,另一个也同时滚动)?

How can I link 2 Listview components, so that their scrolling is in sync (when I scroll one, the other scrolls too at the same time)?

所以基本上我需要一种方法:

So basically I need a way to:

1) 监听Listview1的滚动事件2)为Listview2设置相同的滚动偏移

1) Monitor the scrolling event of Listview1 2) Set the same scrolling offset to Listview2

我在 Stackoverflow 上找到了一些示例,但它们指的是 WPF 或 WinRT,它们与我的应用不兼容.

I found some examples here on Stackoverflow but they either refer to WPF, or WinRT and they are not compatible with my app.

谢谢!

推荐答案

您在问题中描述的内容可以通过以下步骤完成:

What you have described in your question can be done by the following steps:

  1. ListView 中找到 ScrollViewer(从 这个答案).
  2. 订阅 ViewChanged 事件.
  3. 在事件处理程序中,在另一个 ScrollViewer 上调用 ChangeView.
  1. Find the ScrollViewer inside the ListView (check out GetScrollViewer from this answer).
  2. Subscribe to the ViewChanged event.
  3. Inside the event handler, call ChangeView on the other ScrollViewer.

假设您正在垂直滚动 -

Assume you are scrolling vertically -

private void SyncScrollViewers()
{
    var scrollViewer1 = MyListView1.GetScrollViewer();
    var scrollViewer2 = MyListView2.GetScrollViewer();

    scrollViewer1.ViewChanged += (s, e) =>
    {
        scrollViewer2.ChangeView(null, scrollViewer1.VerticalOffset, null, false);
    };
}

这篇关于我可以在 UWP 中的多个 Listview 项目之间同步滚动吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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