WPF - EllipseGeometry animation in C# using a Storyboard -
i need scale ellipsegeometry in c# scaletransform, doesn't works. here's code:
xaml:
<image x:name="rock" stretch="none"> <image.clip> <ellipsegeometry x:name="rockclip" radiusx="100" radiusy="100" center="200,150"> <ellipsegeometry.transform> <scaletransform/> </ellipsegeometry.transform> </ellipsegeometry> </image.clip> </image>
c#:
doubleanimation scalex = new doubleanimation(); scalex.begintime = timespan.frommilliseconds(frommills); scalex.duration = new duration(timespan.frommilliseconds(2000)); scalex.from = 0.0; scalex.to = 1.0; scalex.setvalue(storyboard.targetproperty, rockclip); scalex.setvalue(storyboard.targetpropertyproperty, new propertypath("(ellipsegeometry.transform).(scaletransform.scalex)")); doubleanimation scaley = new doubleanimation(); scaley.begintime = timespan.frommilliseconds(frommills); scaley.duration = new duration(timespan.frommilliseconds(2000)); scaley.from = 0.0; scaley.to = 1.0; scaley.setvalue(storyboard.targetproperty, rockclip); scaley.setvalue(storyboard.targetpropertyproperty, new propertypath("(ellipsegeometry.transform).(scaletransform.scaley)")); storyboard storyboard = new storyboard(); storyboard.children.add(scalex); storyboard.children.add(scaley); storyboard.completed += storyboard_completed; animation.begin();
the storyboard_completed event triggered there no animation on ellipsegeometry.
where problem?
i can animate ellipsegeometry in way:
doubleanimation scale = new doubleanimation(); scale.from = 0; scale.to = 40; scale.duration = new duration(timespan.frommilliseconds(5000)); rockclip.beginanimation(ellipsegeometry.radiusxproperty, scale); rockclip.beginanimation(ellipsegeometry.radiusyproperty, scale);
i need put doubleanimation in storyboard, don't know how.
thanks.
it works if use image control (instead of geometry) target element:
var scalex = new doubleanimation(); scalex.begintime = timespan.frommilliseconds(frommills); scalex.duration = timespan.fromseconds(2); scalex.from = 0.0; scalex.to = 1.0; storyboard.settarget(scalex, rock); storyboard.settargetproperty(scalex, new propertypath("clip.transform.scalex")); var scaley = new doubleanimation(); scaley.begintime = timespan.frommilliseconds(frommills); scaley.duration = timespan.fromseconds(2); scaley.from = 0.0; scaley.to = 1.0; storyboard.settarget(scaley, rock); storyboard.settargetproperty(scaley, new propertypath("clip.transform.scaley")); var storyboard = new storyboard(); storyboard.children.add(scalex); storyboard.children.add(scaley); storyboard.begin();
however, way may name scaletransform
<ellipsegeometry.transform> <scaletransform x:name="scale"/> </ellipsegeometry.transform>
and run animations this:
var scaleanimation = new doubleanimation { begintime = timespan.frommilliseconds(frommills), duration = timespan.fromseconds(2), = 0.0, = 1.0 }; scale.beginanimation(scaletransform.scalexproperty, scaleanimation); scale.beginanimation(scaletransform.scaleyproperty, scaleanimation);
edit: in order animate radiusx
, radiusy
properties means of storyboard, write this:
var radiusxanimation = new doubleanimation(); radiusxanimation.begintime = timespan.frommilliseconds(frommills); radiusxanimation.duration = timespan.fromseconds(2); radiusxanimation.from = 0; radiusxanimation.to = 100; storyboard.settarget(radiusxanimation, rock); storyboard.settargetproperty(radiusxanimation, new propertypath("clip.radiusx")); var radiusyanimation = new doubleanimation(); radiusyanimation.begintime = timespan.frommilliseconds(frommills); radiusyanimation.duration = timespan.fromseconds(2); radiusyanimation.from = 0; radiusyanimation.to = 100; storyboard.settarget(radiusyanimation, rock); storyboard.settargetproperty(radiusyanimation, new propertypath("clip.radiusy")); var storyboard = new storyboard(); storyboard.children.add(radiusxanimation); storyboard.children.add(radiusyanimation); storyboard.begin();
Comments
Post a Comment