c# - How to animate TranslateTransform and ScaleTransform in WPF -


i'm trying animate translatetransform , scaletransform of rectangle @ same time using storyboard in code-behind. studied similar questions how i'm still stuck @ first step.

<grid>     <grid.rowdefinitions>         <rowdefinition height="*"/>         <rowdefinition height="*"/>     </grid.rowdefinitions>     <rectangle x:name="myrectangle" width="100" height="100" fill="aqua"></rectangle>     <button grid.row="1" content="animate" click="buttonbase_onclick"/> </grid>      private void buttonbase_onclick(object sender, routedeventargs e)     {         var translate_x = new doubleanimation()         {             = 0,             = 100,             duration = timespan.fromseconds(5),         };         var translate_y = new doubleanimation()         {             = 0,             = 100,             duration = timespan.fromseconds(5),         };          var scale_x = new doubleanimation()         {             = 1,             = 2,             duration = timespan.fromseconds(5),         };          var scale_y = new doubleanimation()         {             = 1,             = 2,             duration = timespan.fromseconds(5),         };     } 

in xaml, give rectangle transformgroup:

<rectangle x:name="myrectangle" width="100" height="100" fill="chartreuse">     <rectangle.rendertransform>         <transformgroup>             <scaletransform x:name="rectscale"/>             <translatetransform x:name="recttrans"/>         </transformgroup>    </rectangle.rendertransform> </rectangle> 

in code-behind, use beginanimation method on transforms:

rectscale.beginanimation(scaletransform.scalexproperty, scale_x); rectscale.beginanimation(scaletransform.scaleyproperty, scale_y); recttrans.beginanimation(translatetransform.xproperty, translate_x); recttrans.beginanimation(translatetransform.yproperty, translate_y); 

Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -