wpf - Trigger an EventTrigger by an AttachedEvent -


i have a custom panel raises routedevent defined globally in static class :

 public class compressitemstofitstackpanel : stackpanel  {     protected override size arrangeoverride(size arrangesize)     {                 // logic          // raise attached event              customeventmanager.raisearrangeevent(this);         return base.arrangeoverride(arrangesize);      }           } 

my attached event:

 public static class customeventmanager {                             public static readonly routedevent arrangeevent = eventmanager.registerroutedevent("arrange",                                 routingstrategy.bubble,                                 typeof(routedeventhandler),                                 typeof(customeventmanager));      internal static void raisearrangeevent(uielement target)     {         var args = new routedeventargs(arrangeevent);         target.raiseevent(args);                 }        }  

this panel items panel items control , itemstemplate eventtrigger wan't fire when attached event raised:

  <datatemplate datatype="{x:type local:checker}" x:key="checkertempalte">      <ellipse x:name="ellipse" style="{staticresource checkerstyle}">         <ellipse.triggers>             <eventtrigger routedevent="local:customeventmanager.arrange">                 <beginstoryboard>                     <storyboard>                         <doubleanimationusingkeyframes                                      storyboard.targetproperty="(uielement.rendertransform).(transformgroup.children)[3].(translatetransform.y)"                                      storyboard.targetname="ellipse"                                 >                             <easingdoublekeyframe keytime="0:0:0" value="0" />                             <easingdoublekeyframe keytime="0:0:1" value="{binding val}" />                         </doubleanimationusingkeyframes>                     </storyboard>                 </beginstoryboard>             </eventtrigger>                             </ellipse.triggers>             </ellipse> 

the event trigger not triggered ,

maybe i'm not using attachedevents correctly or not declared correctly need event panel propagate , trigger eventtriggers in child elements ,

any ideas i'm doing wrong ?

edit :

after dkozl's insight came conclusion need addxxxhandler , removexxxhandler in order xaml add/ remove handler eventtrigger

    public static void addarrangehandler(dependencyobject d, routedeventhandler handler)     {         uielement uie = d uielement;         if (uie != null)         {             uie.addhandler(customeventmanager.arrangeevent, handler);         }     }      public static void removearrangehandler(dependencyobject d, routedeventhandler handler)     {         uielement uie = d uielement;         if (uie != null)         {             uie.removehandler(customeventmanager.arrangeevent, handler);         }     }  

but still nothing happens , , never reach these methods .

edit 2 :

thanks dkozl's comments below ,

the event raised each child element , since ellipses down visual tree .

  protected override size arrangeoverride(size arrangesize)   {                           foreach (uielement child in children)       {                                    customeventmanager.raisearrangeevent(child);                                                   }    } 

but still nothing happens , iv'e tested 'storyboard' giving 'eventtrigger' 'mouseenter' event , moving mouse on element , works fine.

still , raising event on each ellipse still not work ... ideas ?

another point of interest child elements 'checker' type , not ellipse datatemplate represents , don't how 'checker' considered uielement .?

what you've created standard routedevent, not attached one. add/remove handler different attached events. you'll need 2 separate methods (addarrangechildrenhandler , removearrangechildrenhandler). has been explained on msdn site

update: i've copied updated ellipse definition , customeventmanager class application, added test button calls customeventmanager.raisearrangeevent(ellipse); when clicked , works me.

i had add ellipse.rendertransorm of transformgroup, fourth transformation being translatetransform make work in example

update2: event raised on panel ellipse placed means bubbling event never reach start panel , go visual tree window never reaching children of panel


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -