none
Animating many properties of an object RRS feed

  • General discussion

  • Hi,

    I'm going to change the properties of my object (for example a rectangle) - the position on the screen and its scale. It's easy:


    TransformGroup tg = new TransformGroup();
                tg.Children.Add(new TranslateTransform(20, 100)); 
                tg.Children.Add(new ScaleTransform(2.0,2.0));
                rect.RenderTransform = tg;

    But now I want it to animate and here is the worst thing... I found many tutorials on how to animate one property of an object. Suffice to create a TranslateTransform object (when I want to change the position), create a Storyboard, a DoubleAnimation and compose it together ;). But I have no idea how to make it work with two (or more) properties using TransformGroup... I found a solution here: http://simplesilverlight.wordpress.com/2007/12/18/animate-multiple-transforms-from-c-wpf/ but that's not what I was looking for. I want to use a Storyboard in order to have a control over the animation.

    Please, give me some links to any tutorials or a few words of explanation...

    Thanks!

    EDIT:

    Just wanted to add that I want to write that in C#...
    • Edited by Jajo.ovo Thursday, July 31, 2008 4:45 PM More information ;)
    • Changed type Marco Zhou Thursday, August 7, 2008 9:59 AM OP doesn't revert back
    Thursday, July 31, 2008 4:03 PM

All replies

  • Hi,

    you can't animate the TransformGroup itself. Instead, you have to access the single transforms.
    The best way to do this would be creating the transforms in XAML, giving them names and finally referring to those names from your Storyboard, e.g.
    Storyboard.TargetName="myTranslation"
    and
    Storyboard.TargetProperty="TranslateTransform.X"

    If you insist doing this via code, keep references to the objects you want to animate, then call BeginAnimation on them:

    ScaleTransform scale = new ScaleTransform ();
    DoubleAnimation ani = new DoubleAnimation();
    // configure your animation here..
    scale.BeginAnimation (ScaleTransform.ScaleXProperty, ani);

    Andrej
    Thursday, July 31, 2008 5:11 PM
  • Andrej.K said:

    If you insist doing this via code, keep references to the objects you want to animate, then call BeginAnimation on them:

    ScaleTransform scale = new ScaleTransform ();
    DoubleAnimation ani = new DoubleAnimation();
    // configure your animation here..
    scale.BeginAnimation (ScaleTransform.ScaleXProperty, ani);


    That's what I found in that link, but in this way I loose the control over the animation, i.e. I can't stop it anymore whenever I want to or accelerate it. With Storyboard I got such methods as Stop, Pause, Resume, SetSpeedRatio and so on, and so on...


    EDIT:

    There must be a way to do that...

    I will explain what I want to achieve, maybe that will help you. I've got a Canvas. OnMouseWheel I want to to zoom in and out. OnMouseMove (when the mouse is clicked) I want it to move on the screen. When I just zoom it or when I just drag it everything is ok. But when after zooming I try to drag it, there's no zoom anymore ;). The program just forgets about it as though I haven't zoomed it...
    • Edited by Jajo.ovo Thursday, July 31, 2008 5:44 PM More explanation
    Thursday, July 31, 2008 5:16 PM
  • Storyboard could hold multiple AnimationTimeline instances, which should be able to fulfill your requirement, and you can also start Storyboard at codehehind, could you please elaborate which specific issue you have with Storyboard?

    Thanks
    Monday, August 4, 2008 9:32 AM
  • We are changing the issue type to “Comment” because you have not followed up with the necessary information. If you have more time to look at the issue and provide more information, please feel free to change the issue type back to “Question” by clicking the "Options" link at the top of your post, and selecting "Change Type" menu item from the pop menu. If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.

     

    Thank you!

    Thursday, August 7, 2008 9:59 AM