windows - How can I add a storyboard animation to my page resources in C#, then call it again later? -



windows - How can I add a storyboard animation to my page resources in C#, then call it again later? -

hubpage landing page. on hubpage.xaml, have grid of 3x3, containing rectangle, i'm calling "cell". in hubpage.xaml.cs, particularly in hubpage() constructor, create storyboard each cell:

createstoryboardforcell("column0row0"); createstoryboardforcell("column0row1"); ... createstoryboardforcell("column2row2");

i want add together storyboard page.resources, in xaml, attempting c#. now, here createstoryboardforcell implementation:

private void createstoryboardforcell(string cellname) { // create 2 doubleanimations, 1 scalex , 1 scaley, , set properties. duration duration = new duration(timespan.fromseconds(0.2)); doubleanimation mydoubleanimation1 = new doubleanimation(); doubleanimation mydoubleanimation2 = new doubleanimation(); mydoubleanimation1.duration = duration; mydoubleanimation2.duration = duration; storyboard sb = new storyboard(); sb.duration = duration; sb.children.add(mydoubleanimation1); sb.children.add(mydoubleanimation2); // set targets of animations storyboard.settarget(mydoubleanimation1, column0row0); storyboard.settarget(mydoubleanimation2, column0row0); // set attached properties of scalex , scaley // target properties of 2 respective doubleanimations storyboard.settargetproperty(mydoubleanimation1, "(uielement.rendertransform).(compositetransform.scalex)"); storyboard.settargetproperty(mydoubleanimation2, "(uielement.rendertransform).(compositetransform.scaley)"); mydoubleanimation1.to = 15; mydoubleanimation2.to = 22; // create storyboard resource. seek { pageroot.resources.add("story" + cellname, sb); } grab (exception e) { status.text = "error adding storyboard resource cell" + cellname + ": " + e.message; } }

pageroot hubpage.xaml: page x:name="pageroot", etc. not exception when adding resource, cannot see resource when set breakpoint, assume added successfully, can see count increasing, , no exception thrown.

moving on, have click handler each column cell, infer row , column number , seek start corresponding storyboard added page resource earlier. here code:

private void column1_cell_click(object sender, routedeventargs e) { rectangle rect = sender rectangle; int x = (int)rect.getvalue(grid.rowproperty); int y = (int)rect.getvalue(grid.columnproperty); string storyboardname = "storycolumn" + y + "row" + x; storyboard storyboard = (storyboard)findname(storyboardname); storyboard.begin(); }

but findname phone call returns null storyboard. missing here?

i've written code you.i hope benefits business

here code:

<grid> <grid.columndefinitions> <columndefinition x:name="column0row0"/> <columndefinition x:name="column0row1"/> <columndefinition x:name="column0row2"/> </grid.columndefinitions> <grid.rowdefinitions> <rowdefinition/> <rowdefinition/> <rowdefinition/> </grid.rowdefinitions> <rectangle fill="pink" x:name="rectangle" mouseleftbuttondown="rectangle_mouseleftbuttondown"/> <rectangle grid.column="1" grid.row="1" fill="coral" mouseleftbuttondown="rectangle_mouseleftbuttondown"/> <rectangle grid.column="2" grid.row="2" fill="orange" mouseleftbuttondown="rectangle_mouseleftbuttondown"/> </grid>

code behind :

private void createstoryboardforcell(rectangle target) { scaletransform trans = new scaletransform(); target.rendertransform = trans; doubleanimation anim = new doubleanimation(1, 2, timespan.frommilliseconds(1000)); trans.beginanimation(scaletransform.scalexproperty, anim); trans.beginanimation(scaletransform.scaleyproperty, anim); } private void rectangle_mouseleftbuttondown(object sender, mousebuttoneventargs e) { createstoryboardforcell((rectangle)sender); }

c# windows xaml animation storyboard

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -