c# - Stop WPF animation, storyboard begin in xaml but stopping it in codebehind? -


i created animation storyboard in xaml file. story board begins on button.click. stop animation trying stop storyboard on custom event in code behind. code not throwing exception when event got fired animation still goes continue.

i think issue stop method. stop required same object begins animation stop it. here storyboard begin in wpf xaml , stopping in code behind.

any solution, how xaml object in code behind or alternative solution this??

xaml code:

<canvas.triggers>             <eventtrigger routedevent="button.click" sourcename="scanbutton">                 <eventtrigger.actions>                     <beginstoryboard >                         <storyboard  name="movingserver" storyboard.targetname="imagemove" repeatbehavior="forever" >                             <doubleanimation storyboard.targetproperty="(canvas.left)" duration="0:0:2" from="30" to="300" begintime="0:0:0" />                             <doubleanimation storyboard.targetproperty="(canvas.left)" duration="0:0:5" from="300" to="300" begintime="0:0:5" />                             <doubleanimation storyboard.targetproperty="(canvas.left)" duration="0:0:2" from="300" to="600" begintime="0:0:7" />                             <doubleanimation storyboard.targetproperty="opacity" duration="0:0:2" from="1" to="0" begintime="0:0:7" />                         </storyboard>                     </beginstoryboard>                 </eventtrigger.actions>             </eventtrigger> 

code behind:

    private void eventpublisher_onscanningfinish(object sender, eventargs args)     {         dispatcher.invoke(dispatcherpriority.normal, (action)delegate() { this.stopscanninganimation(); });     }      private void stopscanninganimation()     {          serverview.storyboardserverscrolling.stop(this); //---------- not working          //this.serverview.server1static.visibility = system.windows.visibility.hidden;         //this.serverview.server2static.visibility = system.windows.visibility.hidden;         //this.serverview.server3scrolling.visibility = system.windows.visibility.hidden;         //this.serverview.searchingglass.visibility = system.windows.visibility.hidden;     } 

define storyboard static resource,

<mycontrol.resources>                         <storyboard key="movingserver" storyboard.targetname="imagemove" repeatbehavior="forever" >                             <doubleanimation storyboard.targetproperty="(canvas.left)" duration="0:0:2" from="30" to="300" begintime="0:0:0" />                             <doubleanimation storyboard.targetproperty="(canvas.left)" duration="0:0:5" from="300" to="300" begintime="0:0:5" />                             <doubleanimation storyboard.targetproperty="(canvas.left)" duration="0:0:2" from="300" to="600" begintime="0:0:7" />                             <doubleanimation storyboard.targetproperty="opacity" duration="0:0:2" from="1" to="0" begintime="0:0:7" />                         </storyboard> </mycontrol.resources> 

and reference backend code follows :

storyboard board = (storyboard)this.findresource("movingserver"); board.stop(); 

start animation 'click' event of button (i don't know if defined in xaml, here's how done if did)

<button x:name="scanbutton" onclick="scanbutton_click"></button>   protected void scanbutton_click(object sender, eventargs e) {     storyboard board = (storyboard)this.findresource("movingserver");     board.start(); } 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -