c# - WPF commands globally available -


i have window element contains ribbonmenue. within window there usercontrols. in 1 of usercontrol datagrid. created icommand lets me add , delete rows datagrid.

the problem somehow need access these icommands ribbonmenu, can access them @ "higher level" (the window) since declared , bound viewmodel bound usercontrol.

how can create icommands can called globally? note icommand needs reference viewmodel behind usercontrol since need delete rows , on.

image makes bit clearer hope

the traditional mvvm way "global commands" use compositecommand. you'll have globalcommands.cs file contains static class called globalcommands.

in it, you'll have icommand properties return compositecommand instance. then, vm interested in command can attach in thier constructor: globalcommands.somecommand.registercommand(...). ui attach globalcommands commands.

so globalcommands hold compositecommand empty shell / holder command , vms register normal relaycommand composite command , handle command. multiple vms can register same command , called.

the more advanced compositecommand implementations include iactiveaware feature can make compositecommand send canexecute/execute "active" vm's.

i believe compositecommand came prism, many folks (including myself) have broken out use in non prism applications.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -