开发者

Is it possible to apply a storyboard to an element that is created after application start?

开发者 https://www.devze.com 2023-03-17 03:37 出处:网络
Basically, Ive got a load of polygons on a canvas (the number of which is determined by the 开发者_运维问答user clicking on the canvas for every polygon he/she wants). I then want to be able to animat

Basically, Ive got a load of polygons on a canvas (the number of which is determined by the 开发者_运维问答user clicking on the canvas for every polygon he/she wants). I then want to be able to animate these polygons once the user click a 'Play' button. Any ideas on how to do this? Or whether it is possible? So far I've only learnt how to apply storyboard to elements that are created before the application is started.


Hopefully this will help: Creating an Animation in Procedural Code

You need either one storyboard instance per polygon (if you want to control them independently) or you need to add multiple DoubleAnimations, to one storyboard, each targetting one polygon's x or y position.

It all depends what sort of animation you want to show. Can you elaborate?


Here is an example...

<Window.Resources>
    <Storyboard x:Key="storyboard">
                    <DoubleAnimation Storyboard.TargetName="someElement" Storyboard.TargetProperty="Angle" From="0.00" To="-90" Duration="00:00:0.5" AccelerationRatio="1" ></DoubleAnimation>
                    <DoubleAnimation Storyboard.TargetName="someOtherElement" Storyboard.TargetProperty="Angle" From="90" To="0" Duration="00:00:0.5"  DecelerationRatio="0.5" ></DoubleAnimation>
                </Storyboard>
</Window.Resources>

Storyboard sb = (Storyboard)this.FindResource("storyboard");
DoubleAnimation da1 = (DoubleAnimation)sb.Children[0];
DoubleAnimation da2 = (DoubleAnimation)sb.Children[1];

da1.SetValue(Storyboard.TargetNameProperty, "changeTargetElement");
da2.SetValue(Storyboard.TargetNameProperty, "changeOtherTargetElement");
sb.Begin(this, true);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号