Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two-Way Binding Of VerticalOffset Property on ScrollViewer?

I have a View and a ViewModel in Silverlight 3.0.

The view contains a standard ScrollViewer, which contains dynamic content.

Depending on the content within the ScrollViewer, the user could have scrolled half way down the content, and then performed an action that causes the ScrollViewer to load new content, but the ScrollViewer does not automatically scroll to the top.

I want to be able to bind to the VerticalOffset property, but it is read-only. Any ideas on attachable behavior? Any ideas?

Thanks.

like image 302
Chris Avatar asked Feb 03 '23 07:02

Chris


1 Answers

The following blog post provides an attached behaviour that exposes the vertical / horizontal offsets of a scrollviewer so that you can bind to them, or set them in code:

http://blog.scottlogic.com/2010/07/21/exposing-and-binding-to-a-silverlight-scrollviewers-scrollbars.html

This allows the following markup:

<ScrollViewer 
    local:ScrollViewerBinding.VerticalOffset="{Binding YPosition, Mode=TwoWay}"
    local:ScrollViewerBinding.HorizontalOffset="{Binding XPosition, Mode=TwoWay}">
    <!-- Big content goes here! -->
</ScrollViewer>
like image 126
ColinE Avatar answered Feb 05 '23 19:02

ColinE