locked
Synchronising scrolling on multiple ScrollViewers (dynoben) - 1/15/2007 10:28 AM PST RRS feed

  • Question

  • By: dynoben

    Hi there,
    
    I'm trying to link two (or more) ScrollViewers (of the same size and content 
    size)  so the vertical and horizontal offsets are kept in sync .  i.e. moving 
    a scrollbar on one of the Scrollviewers auto scrolls the other ScrollViewers. 
     I've done this in HTML previously but the VerticalOffset property that looks 
    like it would do the trick is read only.
    
    Any ideas?
    Tuesday, February 19, 2008 7:35 PM

Answers

  • By: Lingesh Palaniappan (MS)

    Hi,
    I had to write some code to get it working. This is what I did:
    I added an event handler to the ScrollChanged event of one of the scroll
    viewer(You can do this in blend. Once the event handler is added the project
    is opened up in VS). In VS I called the function ScrollToVerticalOffset and
    as a parameter to the function I passed the source scroll viewer's
    VerticalOffset property.

    The code looks like the following:

    private void scroll_changed(object sender, ScrollChangedEventArgs e)
    {
    this.myscrollviewer.ScrollToVerticalOffset(this.source.VerticalOffset);
    }

    One slight modification that you can do is you can cast the sender to
    scrollviewer and that will be the scrollviewer whose offset has changed. Now
    using this scrollviewers offset you can change the offset of all other
    scrollviewers using just the one function.
    Hope this helps.
    Thanks!
    regards,
    Lingesh

    "dynoben" <dynoben@discussions.microsoft.com> wrote in message
    news:AE45755A-AD46-4A7E-8AB5-51064363F541@microsoft.com...
    > Hi there,
    >
    > I'm trying to link two (or more) ScrollViewers (of the same size and
    > content
    > size) so the vertical and horizontal offsets are kept in sync . i.e.
    > moving
    > a scrollbar on one of the Scrollviewers auto scrolls the other
    > ScrollViewers.
    > I've done this in HTML previously but the VerticalOffset property that
    > looks
    > like it would do the trick is read only.
    >
    > Any ideas?
    Tuesday, February 19, 2008 10:27 PM

All replies

  • By: Lingesh Palaniappan (MS)

    Hi,
    I had to write some code to get it working. This is what I did:
    I added an event handler to the ScrollChanged event of one of the scroll
    viewer(You can do this in blend. Once the event handler is added the project
    is opened up in VS). In VS I called the function ScrollToVerticalOffset and
    as a parameter to the function I passed the source scroll viewer's
    VerticalOffset property.

    The code looks like the following:

    private void scroll_changed(object sender, ScrollChangedEventArgs e)
    {
    this.myscrollviewer.ScrollToVerticalOffset(this.source.VerticalOffset);
    }

    One slight modification that you can do is you can cast the sender to
    scrollviewer and that will be the scrollviewer whose offset has changed. Now
    using this scrollviewers offset you can change the offset of all other
    scrollviewers using just the one function.
    Hope this helps.
    Thanks!
    regards,
    Lingesh

    "dynoben" <dynoben@discussions.microsoft.com> wrote in message
    news:AE45755A-AD46-4A7E-8AB5-51064363F541@microsoft.com...
    > Hi there,
    >
    > I'm trying to link two (or more) ScrollViewers (of the same size and
    > content
    > size) so the vertical and horizontal offsets are kept in sync . i.e.
    > moving
    > a scrollbar on one of the Scrollviewers auto scrolls the other
    > ScrollViewers.
    > I've done this in HTML previously but the VerticalOffset property that
    > looks
    > like it would do the trick is read only.
    >
    > Any ideas?
    Tuesday, February 19, 2008 10:27 PM
  • By: dynoben

    Hiya,
    
    Yeah, I already had that event handler but it still wasn't working.  Turns 
    out I had set the VerticalScrollBarVisibility property on the slave 
    ScrollViewer to "Disabled", I changed it to "Hidden" and it now works fine.
    
    Thanks for your prompt response.
    Ben
    
    "Lingesh Palaniappan (MS)" wrote:
    
    > Hi,
    > I had to write some code to get it working. This is what I did:
    > I added an event handler to the ScrollChanged event of one of the scroll 
    > viewer(You can do this in blend. Once the event handler is added the project 
    > is opened up in VS). In VS I called the function ScrollToVerticalOffset and 
    > as a parameter to the function I passed the source scroll viewer's 
    > VerticalOffset property.
    > 
    > The code looks like the following:
    > 
    >   private void scroll_changed(object sender, ScrollChangedEventArgs e)
    >   {
    >    this.myscrollviewer.ScrollToVerticalOffset(this.source.VerticalOffset);
    >   }
    > 
    > One slight modification that you can do is you can cast the sender to 
    > scrollviewer and that will be the scrollviewer whose offset has changed. Now 
    > using this scrollviewers offset you can change the offset of all other 
    > scrollviewers using just the one function.
    > Hope this helps.
    > Thanks!
    > regards,
    > Lingesh
    > 
    > "dynoben" <dynoben@discussions.microsoft.com> wrote in message 
    > news:AE45755A-AD46-4A7E-8AB5-51064363F541@microsoft.com...
    > > Hi there,
    > >
    > > I'm trying to link two (or more) ScrollViewers (of the same size and 
    > > content
    > > size)  so the vertical and horizontal offsets are kept in sync .  i.e. 
    > > moving
    > > a scrollbar on one of the Scrollviewers auto scrolls the other 
    > > ScrollViewers.
    > > I've done this in HTML previously but the VerticalOffset property that 
    > > looks
    > > like it would do the trick is read only.
    > >
    > > Any ideas? 
    > 
    > 
    > 
    Tuesday, February 19, 2008 10:27 PM