wpf - mvvm with prism: setting view from menu item -
i new wpf world. have context menu in shell below:
<contextmenu> <menuitem header="login" command="{binding workspaceviewsetter}" commandparameter="demoapplication.view.loginview"> <menuitem.icon> <image height="16" width="16" stretch="uniform" source="/images/login.png"/> </menuitem.icon> </menuitem> <menuitem header="modules" itemssource="{binding appmodules}"> <menuitem.icon> <image source="/images/modules.png"/> </menuitem.icon> <menuitem.itemcontainerstyle> <style targettype="menuitem"> <setter property="header" value="{binding modulename}"/> <setter property="command" value="{binding elementname=win, path=datacontext.workspaceviewfromtype}"/> <setter property="commandparameter" value="{binding mainviewtype}"/> </style> </menuitem.itemcontainerstyle> </menuitem> </contextmenu> each element in itemssource appmodules of modules menuitem has property named mainviewtype of type system.type. want change view of region when menuitem gets clicked , thinking of using single icommad in shellviewmodel , passing mainviewtype command parameter. however, above code not working. wondering why modules menuitem gets populated itemssource expected.
i have noticed command binding on login menuitem not working though should have, since itemssource property of modules gets bounded. can please suggest how make work?
context menus aren't on same visual tree rest of window, using elementname in binding won't work. you'll need using placementtarget instead. without knowing how viewmodels structured it's difficult give definitive answer solution like:
<menuitem.itemcontainerstyle> <style targettype="menuitem"> <setter property="header" value="{binding modulename}"/> <setter property="command" value="{binding placementtarget.datacontext.workspaceviewfromtype}"/> <setter property="commandparameter" value="{binding mainviewtype}"/> </style> </menuitem.itemcontainerstyle>
Comments
Post a Comment