c# - Bind Items to MenuItem -> use Command -


i have menuitem, has collection of items in it. looks file -> open menuitem.

so:

  • file
    • open
      • open database
        • file 1
        • file 2
        • file 3

xaml code:

<menu> <menuitem header="file">     <menuitem header="open">         <menuitem header="from database" itemssource="{binding ocfragebogen}"/>     </menuitem> </menuitem> </menu> 

i want call command, when specific item has been clicked. example: user clicks on file 1, command should called "file 1" command parameter.

viewmodel contains items, want display in menuitem "collection"

private observablecollection<string> _ocfragebogen; public observablecollection<string> ocfragebogen {         {         if (_ocfragebogen == null)             _ocfragebogen = new observablecollection<string>();         return _ocfragebogen;     }     set     {         _ocfragebogen = value;         raisepropertychanged(() => ocfragebogen);     } } 

to make clear: when user clicks on item (from itemssource) in menuitem, command should called want clicked item.

edit: have use command call method (relaycommand) in viewmodel? want used when item itemssource has been clicked + want pass clicked item method.

this should work you

<menuitem header="from database"            itemssource="{binding youritemsource}">     <menuitem.itemcontainerstyle>         <style targettype="menuitem">             <setter property="command" value="{binding relativesource={relativesource mode=findancestor, ancestortype=menuitem}, path=datacontext.yourcommandname}"></setter>             <setter property="commandparameter" value="{binding}"></setter>          </style>      </menuitem.itemcontainerstyle> </menuitem> 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -