Posts: 3
Threads: 1
Joined: Oct 2011
Reputation:
0
I'd like to create custom animations for panning and zooming because the built-in animations are linear and I need to use an easing function. I've tried animating the ZoomPanel.UsedViewboxEx object but it causes the zoom panel to become very out of sync. After directly modifying UsedViewboxEx.Viewbox, mouse interactions for zooming and panning on the ZoomPanel stop working.
Is there any other way to use custom panning animations?
Thanks
Posts: 738
Threads: 8
Joined: Sep 2009
Reputation:
45
It is possible to create custom animations with deriving your own class from ZoomPanel and override the StartAnimation and StopAnimation methods.
For example:
public class MyZoomPanel : ZoomPanel
{
protected override void StartAnimation(Rect from, Rect to, double startRotationAngle, double endRotationAngle, TimeSpan duration)
{
// Start CompositionTarget.Rendering event
}
protected override void StopAnimation()
{
// Stop animation
}
}
The StartAnimation method gets all the needed properties to animate the change.
Note that inside Rendering event you must not change the Viewbox property or call SetViewbox. Instead you need to set the viewbox.Viewbox (viewbox - this time with lower character - is a protected ViewboxEx that is used inside ZoomPanel and has its own Viewbox as Rect).
To animate the RotationAngle you can change it directly (no need to set some protected property).
Andrej Benedik
Posts: 3
Threads: 1
Joined: Oct 2011
Reputation:
0
This doesn't seem to do anything other than update the display of the ZoomPanel temporarily. I did this:
override void StartAnimation(...) { viewbox.Viewbox = to; }
override void StopAnimation() {}
But the next time I check zoomPanel.Viewbox or ZoomFactor, they still have the original values before calling the zoom functions, so it looks like the base.StartAnimation method is doing more than just setting the viewbox.Viewbox property. Is there anything else I should be doing?
Thanks again
Posts: 3
Threads: 1
Joined: Oct 2011
Reputation:
0
Andrej,
After playing around a bit more, I discovered that calling SetViewboxNow() instead of setting the viewbox.Viewbox property causes the Viewbox property to get updated correctly and without causing the Viewbox setter to loop forever. I would still rather animate against a property instead of calling the SetViewboxNow method, but this will work out okay.
-Brian
Posts: 19
Threads: 6
Joined: Oct 2011
Reputation:
0
Can you guys post the source code for this? I would like to change the animation easing as well. Maybe this would be a good addition to the control for the next version? Maybe add a property to specify the easing?
Posts: 738
Threads: 8
Joined: Sep 2009
Reputation:
45
The new version of ZoomPanel (v3.3) already uses quintic animation easing.
This version also adds full support for custom animations - the samples on how to use custom animations are also included.
Andrej Benedik