none
ScaleTransform Animation in C#

    Question

  • hi.. Group,

     

    Sorry about another stupid question. I searched the group, there is no answer to use StoryBoard to do scaleTransform animation.

     

    In Xaml, the code likes like:

     

    <Storyboard>

       <DoubleAnimation

            Storyboard.TargetName = "MyAnimatedScaleTransform"

            Storyboard.TargetProperty="(ScaleTransform.ScaleX)"

            To = "3.0", Duration = "0:0:10" AutoReverse="true"/>

    </Storyboard>

     

    How to set the TargetProperty in C#?

     

    Thanks.

    Thursday, June 14, 2007 5:17 PM

Answers

  • Hi,

    I just posted the second installment of a serie of articles about animations which uses a ScaleAnimation for the example. I think you'll find it useful.

    http://www.galasoft-lb.ch/mydotnet/articles/article-2007061401.aspx

    HTH,
    Laurent
    Thursday, June 14, 2007 7:21 PM
  • Sure, you're looking for the Completed event. 

     

    Something like:

     

    Code Snippet

    ...

    myDoubleAnimation.Completed += new EventHandler(myAnimation_Completed);

    ...

     

    void myAnimation_Completed(object sender, EventArgs e) // This can be automatically stubbed out

    {

     

    myAnimation_Completed gets called by the dispatcher as soon as the animation finishes.

     

    Hope this helps!

    Thursday, June 14, 2007 10:47 PM

All replies

  • As a disclaimer I'm not an expert on animation, but I have hit this issue myself.  Here's a snippet that may help:

     

    Code Snippet

    ScaleTransform scaleTran = new ScaleTransform(8.0, 8.0);

    poly.RenderTransform = scaleTran; // This sets the target to a polygon I already declared...

    MainScreen.Children.Add(poly);

    scaleTran.BeginAnimation(ScaleTransform.ScaleYProperty, scaleYAnim);

    scaleTran.BeginAnimation(ScaleTransform.ScaleXProperty, scaleXAnim);

     

     

    Your first argument to BeginAnimation specifies the target DependencyProperty (in here it's ScaleX and ScaleY Properties), I already declared ScaleY/XAnim as DoubleAnimations.    Setting poly.RenderTransform tells scaleTran to work with the polygon I declared.

     

    Hope this helps,

    Matt

    Thursday, June 14, 2007 6:52 PM
  • Hi,

    I just posted the second installment of a serie of articles about animations which uses a ScaleAnimation for the example. I think you'll find it useful.

    http://www.galasoft-lb.ch/mydotnet/articles/article-2007061401.aspx

    HTH,
    Laurent
    Thursday, June 14, 2007 7:21 PM
  • Thanks, Matt.

     

    What I need is an event fired up when animation is finished. If BeginAnimaiton is used, it seems no way to catch up the event. Do you have any idea about it?

     

    Thanks again for your reply.

    Thursday, June 14, 2007 9:20 PM
  • Sure, you're looking for the Completed event. 

     

    Something like:

     

    Code Snippet

    ...

    myDoubleAnimation.Completed += new EventHandler(myAnimation_Completed);

    ...

     

    void myAnimation_Completed(object sender, EventArgs e) // This can be automatically stubbed out

    {

     

    myAnimation_Completed gets called by the dispatcher as soon as the animation finishes.

     

    Hope this helps!

    Thursday, June 14, 2007 10:47 PM