Can I sync scrolling between multiple Listview items in UWP?

为君一笑 提交于 2019-12-06 16:57:17

问题


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) Monitor the scrolling event of Listview1 2) Set the same scrolling offset to Listview2

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

Thank you!


回答1:


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

  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);
    };
}


来源:https://stackoverflow.com/questions/44294614/can-i-sync-scrolling-between-multiple-listview-items-in-uwp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!