Reputation: 47
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!
Upvotes: 0
Views: 1418
Reputation: 39006
What you have described in your question can be done by the following steps:
ScrollViewer
inside the ListView
(check out GetScrollViewer
from this answer).ViewChanged
event.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);
};
}
Upvotes: 3