c# - Activate XAML Storyboard on Button Click (Windows 8 Application) -


basically, how activate simple storyboard animation button, instead of having play automatically? trying normal buttons, toggle buttons , toggle switches here, none have worked.

i intend image of door move right upon clicking button, , move left when clicking again. should repeat behavior indefinitely when clicked.

what goes mainpage.xaml file.

<grid>     <grid.background>         <imagebrush imagesource="assets/1.png"/>     </grid.background>      <image source="assets/rightdoor.png" x:name="rightdoor" horizontalalignment="center" height="1000" margin="276,166,-2665,-398" verticalalignment="top" width="3755">         <image.rendertransform>             <!--<compositetransform x:name="imagetransform"/>-->             <transformgroup>                 <translatetransform x:name="rdformtranslate" x ="1" y="1" />                 <scaletransform x:name ="rdformscale" scalex=".25" scaley=".25" />             </transformgroup>         </image.rendertransform>     </image>  <togglebutton x:name="togglebutton" content="togglebutton" horizontalalignment="left" margin="493,572,0,0" verticalalignment="top" click="togglebtn"/> <button content="button" horizontalalignment="left" margin="772,572,0,0" verticalalignment="top" click="btntest/> <toggleswitch header="toggleswitch" horizontalalignment="left" margin="202,548,0,0" verticalalignment="top" toggled="togglebutton"/> </grid> 

mainpage.xaml.cs file

    private void togglebutton(object sender, windows.ui.xaml.routedeventargs e)     {         storyboard mystoryboard;         mystoryboard = (storyboard)this.resources["rdformtranslate"];            mystoryboard.begin();     }      private void togglebtn(object sender, windows.ui.xaml.routedeventargs e)     {         storyboard mystoryboard;         mystoryboard = (storyboard)this.resources["rdformtranslate"];         mystoryboard.begin();     }      private void btntest(object sender, windows.ui.xaml.routedeventargs e)     {         storyboard mystoryboard;         mystoryboard = (storyboard)this.resources["rdformtranslate"];         mystoryboard.begin();     } 

resource dictionary file...

<storyboard x:name="rdformtranslate">     <doubleanimation storyboard.targetname="rdformtranslate"                                  storyboard.targetproperty="x"                                  from="0" to="500" duration="0:0:1"                                  autoreverse ="true" repeatbehavior="forever" /> </storyboard> 

the application capable of running, upon clicking buttons, "crashes". appreciate in resolving problem.


edit added error comments

an exception of type 'system.runtime.interopservices.comexception' occurred in mscorlib.dll not handled in user code winrt information: e_network_error additional information: unspecified error if there handler exception, program may safely continued.

try changing name of storyboard , make unique. think app crashes when set <doubleanimation storyboard.targetname="rdformtranslate"> same name of storyboard.

also don't need give name translation transform object target x property. try storyboard.targetproperty = "(uielement.rendertransform).(translatetransform.x)". don't need give x default value since setting from property of doubleanimation.

you can safely replace <rendertransform>...</rendertransform> block in xaml <rendertransform><translatetransform/></rendertransform>.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -