问题
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:
- Find the
ScrollViewer
inside theListView
(check outGetScrollViewer
from this answer). - Subscribe to the
ViewChanged
event. - Inside the event handler, call
ChangeView
on the otherScrollViewer
.
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