Scrolling so smooth like the butter on a muffin [How to: Animate the Horizontal/VerticalOffset properties of a ScrollViewer]
**
This blog has moved to a new location and comments have been disabled.
All old posts, new posts, and comments can be found on The blog of dlaa.me.
See you there!
Comments
Anonymous
August 05, 2009
Why don't you make a behavior of this? this way peoples working in blend can reuse it. Just an ideaAnonymous
August 05, 2009
michaudv, According to my current understanding of Blend Behaviors, I could not use them to add the writable DependencyProperty that's necessary to get the desired animate-able behavior. If you know otherwise, a pointer to more information would be great! Either way, that doesn't mean you can't use this solution with Blend! :) Once you've compiled ScrollViewerOffsetMediator into some assembly in your project, you should be able to drop it onto the XAML design surface just like any other element - and then hook it up via the standard Blend mechanisms, and everything should work just fine. Other than the code for ScrollViewerOffsetMediator, my sample is 100% XAML-based - no code required - so the general process should be pretty Blend-friendly. Hope this helps!Anonymous
August 11, 2009
I managed to convert this code to a "real" Blend behavior which cleans up the usage a lot (no need for the ScrollViewerOffsetMediator). I'll try and blog it tonight. But basically it now looks like this: <ScrollViewer> <i:Interaction.Behaviors> <behaviors:MouseScrollViewer /> </i:Interaction.Behaviors> </ScrollViewer>Anonymous
August 11, 2009
Inspired by your approach I blogged my ScrollViewer behavior here: http://www.sharpgis.net/post/2009/08/11/Silverlight-Behaviors-Triggers-and-Actions.aspx I made a few changes to the animation. I only use EaseOut since this gave a better feel to it, and instead of using Grid.Loaded for triggering the storyboard I used the MouseWheel event.Anonymous
August 12, 2009
SharpGIS, Great stuff! Loved the post and thanks very much for following up on this! :)Anonymous
August 11, 2011
If the ScrollViewer was not created in xaml then, when this thing constructs, there is no ScrollViewer. public ScrollViewer ScrollViewer { get { return (ScrollViewer)GetValue(ScrollViewerProperty); returns null since there is no actual scrollviewer control when this runs. FYI.Anonymous
August 12, 2011
WantsMoreSettlesForLess, The code you show is a DependencyProperty getter, not a constructor. It will return null until a value is set - which the example XAML does via a Binding/ElementName, but which could be done in code by setting the property. Hope this helps!Anonymous
May 15, 2012
Thanks man, this just saved me hours and hours in a SL project.Anonymous
June 26, 2013
many thanks great stuff !Anonymous
November 20, 2013
I am WPF newbie. I was looking for an auto-scolling ScrollViewer for some dashboards I am porting to WPF from legacy Windows Forms apps. I was playing wtih animations for a couple weeks before I found your solution. Thank You! Thank You! Thank you for posting this solution! Rich