Forward command to current module

Topics: Prism v4 - WPF 4
Dec 6, 2010 at 3:21 PM


i searched a while but maybe i haven't used the right words. I want to build an application that has a menu with a "New" button. When i have loaded my article view, i want that the new command is forwarded to my article module that creates a new article. If my customer view is currently active, i want that a new customer is created. Can anybody give me some links with samples?


Dec 6, 2010 at 6:36 PM


In this case, you could make use of the DelegateCommand available in Prism. If you need to achieve communication between different modules using commands, you could make the DelegateCommand available through a static class, following the approach described in this chapter from the Prism documentation (under the section named "Making a Command Globally Available").

You might find the Commanding quickstart useful to clarify on how to use DelegateCommands.

I hope you find this helpful.

Guido Leandro Maliandi

Dec 9, 2010 at 10:23 PM
Edited Dec 9, 2010 at 10:24 PM

Hi guide, 


thanks for answering. I only got this working with the  CompositeCommand. This is also used in the commanding sample. But actually i always have only one target for my command. If my customer view is open, i want that the "New"-command will create a new customer. If my article view is open, i want that this new-command is forwared to my

article view to create a new article. If i use the composite command, and i press new, it will create a new customer AND a new article... :-)

Actually it should be like in outlook 2007. if i have my mailview open and i press "New", a new Mail will open. if i have my calendar open, a new calendar entry will open,

when i press the new button.

Is that also possible? Do you have samples for that behaviour?



Dec 10, 2010 at 1:38 PM


The scenario you're describing is possible. You can expose two separate instances of Delegate Command, instead of exposing a single Composite Command that contains both. That way, you can bind the "New Mail" button to the "New Mail Command" and the "New Calendar" button to the "New Calendar Command".

You can find a sample of using different Delegate Commands in the Stock Trader Reference Implementation.

I hope you find this helpful.

Guido Leandro Maliandi

Dec 11, 2010 at 2:09 PM

Well, unfortunately it seems that its not clear what i try to do. I tried to make this with MetaData, but i'm not able to set a command in the meta-data. I also did not find any sample in the stocktrader reference implementation.

I only have ONE single button on my shell. only one. and i have my mainregion of course. my main-region can show a list of articles, and a list of customers (that can be selected with an radio-button). when i press my only single button, and currently my customers are listed, i want that a new customer is created. If i switch over to articles and i press my only single new button, i want that a new article is created.

so i think i have to switch the commands. my customer module provides a "CreateNewCustomerCommand" and my article module provides a "CreateNewArticleCommand". When i click on my customer radio button, i think i have to register my createCustomerCommand. And if i click on my article radio button, i have to deregister createcustomercommand on my single new button, and i have to register my createarticlecommand. Is that right? I hope now its clear what i want. Only one single new button. nothing else. but this single button has different behaviour, depending on the currently visible module... 

Dec 11, 2010 at 3:48 PM

I got it. I have used my GlobalCommands-Class, like writte in the documentation. I have a dictionary for my New-Commands and every module can add its own command. and when i change between my modules, i unregister all commands and register new currently selected module command. so my new button does exactly what i want. it depends on the currently loaded module and creates a new customer, if customer view is visible, otherwise, when article view is visible, it creates a new article. Thank you guido. Prism is cool...

Dec 13, 2010 at 3:30 PM


Thank you for sharing your findings with the rest of the community, as other users might find them useful for their scenarios.

As a side note, you could use a Composite Command instead of creating a dictionary of your own, as it is the implementation that Prism provides for this kind of situations. That way, you could register and unregiser your commands from the Composite Command depending on which view is active, achieving the same behavior that you are explaining.

I hope you find this helpful.

Guido Leandro Maliandi