wpf - Listen to child MenuItem Click -
wpf - Listen to child MenuItem Click -
is there way parent menuitem notified when kid menuitem pressed. example, have
<menuitem name='a'> <menuitem name='b' header='...'/> </menuitem>
how can add together event handler notified when b clicked. ideally, click event either tunnel or bubble event not case. solution have in mind hear click event on b , forwards seems pretty heavy handed. there improve solution?
menuitem.click routed event (it bubbles up), can subscribe on first menuitem
, notified of children @ same time.
xaml:
<menuitem name='a' click='onmenuitemclicked'> <menuitem name='b' header='...' /> </menuitem>
c#:
private void onmenuitemclicked(object sender, routedeventargs e) { menuitem item = e.originalsource menuitem; if(null != item) { // handle menu item click here } }
the trick utilize routedeventargs.originalsource
, rather sender
. points command fired event.
wpf event-handling wpf-controls
Comments
Post a Comment