c# - EventTrigger listening to Loaded is triggered twice? -


firstly not sure if triggered twice. loaded event if tested in code behind triggered once (even tried using addhandler accepting third argument handledeventstoo). looks that. have storyboard setup in xaml , should run once when loaded raised. seems start 2 times, second time right after window shown.

i know because have attached property used on doubleanimation inside storyboard. attached property has 1 propertychangedcallback handler. handler triggered twice same value of e.newvalue (from argument). should not triggered twice that. can determine target (which animated) , set attached flag mark has been done on prevent problem of twice triggering, prevent other actual triggers (which not loaded). doubleanimation created newly each trigger (so cannot mark flag on because each time propertychangedcallback triggered time of doubleanimation, no way flag , prevent execution).

here code, simple test:

public class testowner {     public static readonly dependencyproperty testproperty =         dependencyproperty.registerattached("test", typeof(bool), typeof(testowner), new propertymetadata(testchanged));     public static bool gettest(dependencyobject o)     {         return (bool) o.getvalue(testproperty);     }     public static void settest(dependencyobject o, bool value)     {         o.setvalue(testproperty, value);     }     static private void testchanged(dependencyobject o, dependencypropertychangedeventargs e)     { //mark break point here , run it, you'll see it's stopped        //here twice, second time right after window shown.       //...     } } 

xaml:

<frameworkelement>         <frameworkelement.triggers>             <eventtrigger routedevent="frameworkelement.loaded">                 <beginstoryboard>                     <storyboard>                         <doubleanimation from="20000" to="0"                                          duration="00:00:20"                                          storyboard.targetname="somename"                                          local:testowner.test="true"/>                      </storyboard>                 </beginstoryboard>             </eventtrigger>         </frameworkelement.triggers> </frameworkelement> 

i avoid twice triggering understand why so. thank suggestions , help.

well, in fact eventtrigger triggered once. said in question wrong perception. i've found out looks storyboard clones doubleanimation , clones attached properties causing 2 times of entering propertychanged callback handler. first time original doubleanimation. second time cloned doubleanimation, may cloned , run when loaded raised, occurs right after window shown said before.

at least understand problem , more debugging showed me that kind of 2 times entering handler won't affect serious problem. problem seems solved me.


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -