wpf - Start a storyboard from code-behind (xaml.cs), not from view model MVVM -


in wpf have set below style border:

<style targettype="border" x:key="borderblinking">     <style.triggers>         <datatrigger binding="{binding popupblinking}" value="true">             <datatrigger.enteractions>                 <beginstoryboard>                     <storyboard>                                                         <doubleanimation storyboard.targetproperty="opacity"                                          to="0" autoreverse="true" duration="0:0:0.5" speedratio="3" repeatbehavior="3x" />                     </storyboard>                 </beginstoryboard>             </datatrigger.enteractions>             <datatrigger.exitactions>                 <beginstoryboard>                     <storyboard>                         <doubleanimation storyboard.targetproperty="opacity"                                          to="1" autoreverse="true" duration="0:0:0.5" />                     </storyboard>                 </beginstoryboard>             </datatrigger.exitactions>         </datatrigger>     </style.triggers> </style> 

and attach border this:

<border grid.row="2" x:name="popup"          style="{staticresource borderblinking}"         cornerradius="10,10,0,0" height="25" margin="0"         horizontalalignment="center" width="auto"         verticalalignment="center"         borderbrush="darkblue" borderthickness="1"         background="antiquewhite">     <stackpanel  orientation="horizontal" horizontalalignment="center">         <image source="common.images;component/images/info.png" height="20" width="20" stretch="fill"/>         <textblock margin="5" verticalalignment="center" horizontalalignment="left"         background="transparent" fontsize="12"><run text="this custom popup"/></textblock>     </stackpanel> </border> 

then code behind (not view model) want start storyboard. know how start view model through property "popupblinking" (as above in example) bound datatrigger need know how start code-behind (not view model).

i have modified code above , done below:

        <storyboard x:key="blink" >             <doubleanimation storyboard.targetproperty="opacity"                                                   to="0" autoreverse="true" duration="0:0:0.5" speedratio="3" repeatbehavior="3x" />             <doubleanimation storyboard.targetproperty="opacity"                                                  to="1" autoreverse="true" duration="0:0:0.5" />         </storyboard> 

and code-behind:

        storyboard sb = resources["blink"] storyboard;                     sb.begin(this.popup); 

is correct way it?

you directly start animation this:

popup.beginanimation(uielement.opacityproperty,     new doubleanimation     {         = 0,         duration = timespan.fromseconds(0.5),         autoreverse = true,         repeatbehavior = repeatbehavior.forever     }); 

Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -