WPF Controls: How to Reference Resources in Animations? -


i have written control , created storyboard cause animation during triggered events. changes fill of ellipse duration of time. instead of writing new radialgradientbrush each time need change fill, provided 2 of them in resources.

edit: have ellipse main component control , affected animation. it's implementation simple , looks this:

<ellipse name="myellipse" style="{staticresource dimstyle}" /> 

when add storyboard (instead of referencing brush resource), animation works intended. when reference brush resource exception:

"cannot find resource named 'illuminatedstyle'. resource names case sensitive."

inside of storyboard, referenced:

<usercontrol.resources>     <storyboard x:key="foo">         <objectanimationusingkeyframes>             <objectanimationusingkeyframes.keyframes>                 <discreteobjectkeyframe keytime="0:0:0.01" value="{staticresource illuminatedstyle}" />                 <discreteobjectkeyframe keytime="0:0:0.85" value="{staticresource dimstyle}" />             </objectanimationusingkeyframes.keyframes>         </objectanimationusingkeyframes>      </storyboard> </usercontrol.resources> 

the styles closely identical , gradientstop color properties differ i'll provide 1 style example.

the style referenced

<usercontrol.resources>     <style x:key="illuminatedstyle" targettype="ellipse">         <setter property="fill">             <setter.value>                 <radialgradientbrush>                     <gradientstop color="#ff215416" offset="1"/>                     <gradientstop color="#fe38da2e" offset="0"/>                     <gradientstop color="#fe81ff79" offset="0.688"/>                 </radialgradientbrush>             </setter.value>         </setter>     </style> </usercontrol.resources> 

so how correctly reference style such in storyboard?

note: storyboard , style both contained within same usercontrol.resources tag broken out example.

edit
put style before storyboard in usercontrol.resources , exception stating:

  "this freezable cannot frozen.    @ system.windows.freezable.freeze()    @ system.windows.freezable.getcurrentvalueasfrozen()    @ system.windows.media.animation.timelinecollection.getcurrentvalueasfrozencore(freezable source)    @ system.windows.freezable.clonecorecommon(freezable sourcefreezable, boolean usecurrentvalue, boolean clonefrozenvalues)    @ system.windows.media.animation.timeline.getcurrentvalueasfrozencore(freezable sourcefreezable)    @ system.windows.freezable.getcurrentvalueasfrozen()    @ system.windows.media.animation.clock..ctor(timeline timeline)    @ system.windows.media.animation.timelinegroup.allocateclock()    @ system.windows.media.animation.clock.allocateclock(timeline timeline, boolean hascontrollableroot)" 

there 3 reasons why freezable cannot frozen:

  • it has animated or data bound properties.
  • it has properties set dynamic resource.
  • it contains freezable sub-objects cannot frozen.

so, first find out freezable causing trouble , check above.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -