c# - Storyboards can't find ControlTemplate elements -


i've created simple xaml, , works (at least in kaxml). storyboards run when called within xaml, when try access them outside error:

'buttonglow' name cannot found in name scope of 'system.windows.controls.button'. 

i loading xaml stream reader, this:

button x = (button)xamlreader.load(stream); 

and trying run storyboard with:

storyboard pressedbuttonstoryboard =        storyboard)_xamlbutton.template.resources["buttonpressed"]; pressedbuttonstoryboard.begin(_xamlbutton); 

i think problem fields animating in template , storyboard accessing button.

here xaml:

<button xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     xmlns:customcontrols="clr-namespace:pk_rodoment.skinningengine;assembly=pk_rodoment"      width="150" height="55">     <button.resources>         <style targettype="button">             <setter property="control.template">                 <setter.value>                     <controltemplate targettype="button">                         <grid background="#00ffffff">                             <grid.bitmapeffect>                                 <bitmapeffectgroup>                                     <outerglowbitmapeffect x:name="buttonglow" glowcolor="#a0fedf00" glowsize="0"/>                                 </bitmapeffectgroup>                             </grid.bitmapeffect>                             <border x:name="background" margin="1,1,1,1" cornerradius="15">                                 <border.background>                                     <solidcolorbrush color="#ff0062b6"/>                                 </border.background>                                                             </border>                                                         <contentpresenter horizontalalignment="center"                                 margin="{templatebinding control.padding}"                                 verticalalignment="center"                                 content="{templatebinding contentcontrol.content}"                                 contenttemplate="{templatebinding contentcontrol.contenttemplate}"/>                         </grid>                         <controltemplate.resources>                             <storyboard x:key="buttonpressed">                                 <storyboard.children>                                     <doubleanimation duration="0:0:0.4"                                                   fillbehavior="holdend"                                                   storyboard.targetname="buttonglow"                                                   storyboard.targetproperty="glowsize" to="4"/>                                     <coloranimation duration="0:0:0.6"                                                   fillbehavior="holdend"                                                   storyboard.targetname="background"                                                   storyboard.targetproperty="(panel.background).(solidcolorbrush.color)"                                                   to="#ff844800"/>                                 </storyboard.children>                             </storyboard>                             <storyboard x:key="buttonreleased">                                 <storyboard.children>                                     <doubleanimation duration="0:0:0.2"                                                   fillbehavior="holdend"                                                   storyboard.targetname="buttonglow"                                                   storyboard.targetproperty="glowsize" to="0"/>                                     <coloranimation duration="0:0:0.2"                                                   fillbehavior="stop"                                                   storyboard.targetname="background"                                                   storyboard.targetproperty="(panel.background).(solidcolorbrush.color)"                                                   to="#ff0062b6"/>                                 </storyboard.children>                             </storyboard>                         </controltemplate.resources>                         <controltemplate.triggers>                             <trigger property="buttonbase.ispressed" value="true">                                 <trigger.enteractions>                                     <beginstoryboard storyboard="{staticresource buttonpressed}"/>                                 </trigger.enteractions>                                 <trigger.exitactions>                                     <beginstoryboard storyboard="{staticresource buttonreleased}"/>                                 </trigger.exitactions>                             </trigger>                         </controltemplate.triggers>                     </controltemplate>                 </setter.value>             </setter>         </style>     </button.resources>     <dockpanel>         <textblock x:name="textcontent" fontsize="28" foreground="white" >test</textblock>             </dockpanel> </button> 

any suggestions understands wpf , xaml lot better me?

here error stacktrace:

at system.windows.media.animation.storyboard.resolvetargetname(string targetname, inamescope namescope, dependencyobject element) @ system.windows.media.animation.storyboard.clocktreewalkrecursive(clock currentclock, dependencyobject containingobject, inamescope namescope, dependencyobject parentobject, string parentobjectname, propertypath parentpropertypath, handoffbehavior handoffbehavior, hybriddictionary clockmappings, int64 layer) @ system.windows.media.animation.storyboard.clocktreewalkrecursive(clock currentclock, dependencyobject containingobject, inamescope namescope, dependencyobject parentobject, string parentobjectname, propertypath parentpropertypath, handoffbehavior handoffbehavior, hybriddictionary clockmappings, int64 layer) @ system.windows.media.animation.storyboard.begincommon(dependencyobject containingobject, inamescope namescope, handoffbehavior handoffbehavior, boolean iscontrollable, int64 layer) @ system.windows.media.animation.storyboard.begin(frameworkelement containingobject) @ pk_rodoment.skinningengine.buttoncontrolwpf._button_mousedown(object sender, mousebuttoneventargs e) @ system.windows.input.mousebuttoneventargs.invokeeventhandler(delegate generichandler, object generictarget) @ system.windows.routedeventargs.invokehandler(delegate handler, object target) @ system.windows.routedeventhandlerinfo.invokehandler(object target, routedeventargs routedeventargs) @ system.windows.eventroute.invokehandlersimpl(object source, routedeventargs args, boolean reraised) @ system.windows.uielement.raiseeventimpl(dependencyobject sender, routedeventargs args) @ system.windows.uielement.raiseevent(routedeventargs args, boolean trusted) @ system.windows.input.inputmanager.processstagingarea() @ system.windows.input.inputmanager.processinput(inputeventargs input) @ system.windows.input.inputprovidersite.reportinput(inputreport inputreport) @ system.windows.interop.hwndmouseinputprovider.reportinput(intptr hwnd, inputmode mode, int32 timestamp, rawmouseactions actions, int32 x, int32 y, int32 wheel) @ system.windows.interop.hwndmouseinputprovider.filtermessage(intptr hwnd, int32 msg, intptr wparam, intptr lparam, boolean& handled) @ system.windows.interop.hwndsource.inputfiltermessage(intptr hwnd, int32 msg, intptr wparam, intptr lparam, boolean& handled) @ ms.win32.hwndwrapper.wndproc(intptr hwnd, int32 msg, intptr wparam, intptr lparam, boolean& handled) @ ms.win32.hwndsubclass.dispatchercallbackoperation(object o) @ system.windows.threading.exceptionwrapper.internalrealcall(delegate callback, object args, boolean issingleparameter) @ system.windows.threading.exceptionwrapper.trycatchwhen(object source, delegate callback, object args, boolean issingleparameter, delegate catchhandler) @ system.windows.threading.dispatcher.wrappedinvoke(delegate callback, object args, boolean issingleparameter, delegate catchhandler) @ system.windows.threading.dispatcher.invokeimpl(dispatcherpriority priority, timespan timeout, delegate method, object args, boolean issingleparameter) @ system.windows.threading.dispatcher.invoke(dispatcherpriority priority, delegate method, object arg) @ ms.win32.hwndsubclass.subclasswndproc(intptr hwnd, int32 msg, intptr wparam, intptr lparam) @ ms.win32.unsafenativemethods.dispatchmessage(msg& msg) @ system.windows.threading.dispatcher.pushframeimpl(dispatcherframe frame) @ system.windows.threading.dispatcher.pushframe(dispatcherframe frame) @ system.windows.threading.dispatcher.run() @ system.windows.application.rundispatcher(object ignore) @ system.windows.application.runinternal(window window) @ system.windows.application.run(window window) @ system.windows.application.run() @ controltestbed.app.main() in c:\svnprojects\rodomont\controlstestbed\obj\debug\app.g.cs:line 0 @ system.appdomain._nexecuteassembly(assembly assembly, string[] args) @ system.appdomain.executeassembly(string assemblyfile, evidence assemblysecurity, string[] args) @ microsoft.visualstudio.hostingprocess.hostproc.runusersassembly() @ system.threading.threadhelper.threadstart_context(object state) @ system.threading.executioncontext.run(executioncontext executioncontext, contextcallback callback, object state) @ system.threading.threadhelper.threadstart() 

finally found it. when call begin on storyboards reference elements in controltemplate, must pass in control template well.

changing:

pressedbuttonstoryboard.begin(_xamlbutton); 

to:

pressedbuttonstoryboard.begin(_xamlbutton, _xamlbutton.template); 

fixed everything.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -