How can a Caliburn.Micro sub menuitem click call an action on the containing view's viewmodel? -
i have top level menu in shellview , when selecting sub menuitem, call following method on shellviewmodel (a conductor.collection.allactive).
public void selectserver(string pservername) { mdefaultclaimserver = pservername; }
the following not work no method gets called (i have tried various signatures , action parameters) -
<menu name="menu1" dockpanel.dock="top"> <menuitem header="select server" name="claimservers"> <menuitem.itemtemplate> <datatemplate> <!-- need else show class name --> <textblock text="{binding displayname}"> <contentcontrol cal:message.attach="[event click] = [action txtester.shellviewmodel.selectserver($text)]"/> </textblock> </datatemplate> </menuitem.itemtemplate> </menuitem> </menu>
the following call shellviewmodel selectserver method null text of clicked sub menuitem (i tried many other signatures , action parameters) -
<menu name="menu1" dockpanel.dock="top"> <menuitem header="select server" name="claimservers" cal:message.attach="selectserver($this.text)"> <menuitem.itemtemplate> <datatemplate> <!-- need else show class name --> <textblock text="{binding displayname}" /> </datatemplate> </menuitem.itemtemplate> </menuitem> </menu>
i've been struggling long time , can't figure out. can suggest proper combination can pass header text of sub menuitem shellviewmodel selectserver method?
i got trying working, per post rob eisenberg describing "special trick text bound submenus" here - http://caliburnmicro.codeplex.com/discussions/287228
i still love know how trying standard ootb logic if has suggestions, able understand cm better.
basically added bootstrapper configure() overide -
messagebinder.specialvalues.add("$originalsourcecontext", context => { var args = context.eventargs routedeventargs; if (args == null) return null; var fe = args.originalsource frameworkelement; if (fe == null) return null; return fe.datacontext; });
and added xaml -
<menuitem header="_select server" name="claimservers" cal:message.attach="selectserver($originalsourcecontext)" />
and passed header text of sub menuitem wanted.
Comments
Post a Comment