If we want to slide the screen, we need some events.
Like Mouse Move Event
, Mouse Down Event
, Mouse UP event
But the problem is we only can do some animation only when the finger touch the screen, I mean: when It touch the screen move, it will move, when we release it, it will stop(or give it a position let it stop to there). But I want some animation like IPhone main screen do. If our finger slide more fast, the animation more fast (or the animation slide to more far place).
Just like now we use the Photoshop, when the picture zoom out to very large, when we move the hand more fast, it will move to very far.
Another example is it will slow down very slowly, not immediately.
Also it will know my finger sliding fast , or slow….then it will slide slow or fast…
2
Answers
This is a quick example of a control I did for a test with inertia, using a ScrollViewer.
Hope this helps.
I use a modified version of the the code found here in my own programs. Usage is simple as it is an attached behavior and can be applied to a style so that all of your scroll viewers automatically behave in this way. It works by using the same (tunneled) events you mention (
OnPreviewMouseDown
,OnPreviewMouseUp
, andOnPreviewMouseMove
). During the handling ofOnPreviewMouseMove
, inertia is calculated and the scrollbar is moved in a simulated physical manner. There is also a friction property which can be set to change the length of time a scrollbar “glides”.