c# - Looping Storyboard Animation Without Trigger -


this code:

<drawingbrush viewport="0,0,16,16" viewportunits="absolute" stretch="none" tilemode="tile" x:key="dbcheckerboard">     <drawingbrush.drawing>         <drawinggroup>             <geometrydrawing brush="black">                 <geometrydrawing.geometry>                     <geometrygroup>                         <rectanglegeometry rect="0,0,8,8"/>                         <rectanglegeometry rect="8,8,8,8"/>                     </geometrygroup>                 </geometrydrawing.geometry>             </geometrydrawing>         </drawinggroup>     </drawingbrush.drawing> </drawingbrush> <style x:key="scrollingcheckerboardbackground" targettype="control">     <setter property="background" value="{staticresource dbcheckerboard}" />     <style.triggers>         <eventtrigger routedevent="control.loaded">             <beginstoryboard>                 <storyboard>                     <rectanimation storyboard.targetproperty="background.viewport" from="0 0 16 16" to="16 16 16 16" duration="0:0:1" repeatbehavior="forever" />                 </storyboard>             </beginstoryboard>         </eventtrigger>     </style.triggers> </style> 

if apply scrollingcheckerboardbackground style listbox in .xaml file, works fine want apply style in code-behind, when user clicks button. doesn't work because eventtrigger not called.

is there way animate listbox without triggers?

is there way animate listbox without triggers?

no, start animation need specific action or event.

in case try use datatrigger, if tag of listbox showanimation when run animation:

<style x:key="scrollingcheckerboardbackground" targettype="control">     <setter property="background" value="{staticresource dbcheckerboard}" />      <style.triggers>         <datatrigger binding="{binding path=tag, relativesource={relativesource mode=self}}" value="showanimation">             <datatrigger.enteractions>                 <beginstoryboard>                     <storyboard>                         <rectanimation storyboard.targetproperty="background.viewport" from="0 0 16 16" to="16 16 16 16" duration="0:0:1" repeatbehavior="forever" />                     </storyboard>                 </beginstoryboard>             </datatrigger.enteractions>             </datatrigger>     </style.triggers> </style> 

and in code-behind write this:

private void button_click(object sender, routedeventargs e) {     mylistbox.tag = "showanimation"; } 

edit

you can start storyboard in code-behind this:

xaml

<window.resources>     ...     <storyboard x:key="mystoryboard">         <rectanimation storyboard.targetproperty="background.viewport" from="0 0 16 16" to="16 16 16 16" duration="0:0:1" repeatbehavior="forever" />     </storyboard>      <style x:key="scrollingcheckerboardbackground" targettype="control">                                <setter property="background" value="{staticresource dbcheckerboard}" />                </style>         </window.resources>  <grid>     <listbox name="mylistbox"               style="{staticresource scrollingcheckerboardbackground}"               tag="null"               width="100"               height="30" />          <button verticalalignment="bottom" content="click" click="button_click" /> </grid> 

code-behind

public partial class mainwindow : window {     public mainwindow()     {         initializecomponent();               }      private void button_click(object sender, routedeventargs e)     {         var story = (storyboard)this.findresource("mystoryboard");          if (story != null)             story.begin(mylistbox, true);     } } 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -