Guidance on commands needed

Apr 16, 2008 at 10:18 AM
Edited Apr 16, 2008 at 10:48 AM
Hi guys,

I've just started looking at prism. I like it very much!

I was looking at the commanding structure and need some guidance on how I should approach this situation:
Let's say I have a view & controller that allow the user to select something (for instance, a person from the database). It is used by many usecases throughout the system. Let's call this the 'chooser'.
To show the chooser (which is a popup) I would use a command.

My first instinct would be to let the chooser define a multi dispatch command, like StockTraderRICommands. I like to group the commands with the functionality that it will invoke.

However, multiple controllers would register themselves as handlers to this command. But when a button is pressed in viewA, I need ControllerA to take action on it, and not ControllerA,B and C.
So, would the guidance here be to create specific commands per controller?? So let ControllerA create a command 'ChoosePersonForDetailScreen' and ControllerB create 'ChoosePersonForXXXscreen' and let the corresponding views use these specific commands?

I think that might be the best approach, but I do not really like it. I think the view should be able to point to that one command, and let the controller register itself to it. I feel the registermethod could be overloaded with a 'Source' filter: Controller A could register itself like: EmployeeChooserCommands.ChooseEmployee.RegisterCommand(chooseEmployeeCommand, this.View); so that it only get's called when the source of the command is actually the view it is interested in.

At this point I find myself just creating routeduicommands and in my controller, registering a commandbinding on its view to handle them. Is that the correct way for this scenario?
Apr 16, 2008 at 4:24 PM

RBoeke wrote:
Hi guys,

I've just started looking at prism. I like it very much!

I was looking at the commanding structure and need some guidance on how I should approach this situation:
Let's say I have a view & controller that allow the user to select something (for instance, a person from the database). It is used by many usecases throughout the system. Let's call this the 'chooser'.
To show the chooser (which is a popup) I would use a command.

My first instinct would be to let the chooser define a multi dispatch command, like StockTraderRICommands. I like to group the commands with the functionality that it will invoke.

However, multiple controllers would register themselves as handlers to this command. But when a button is pressed in viewA, I need ControllerA to take action on it, and not ControllerA,B and C.
So, would the guidance here be to create specific commands per controller?? So let ControllerA create a command 'ChoosePersonForDetailScreen' and ControllerB create 'ChoosePersonForXXXscreen' and let the corresponding views use these specific commands?

I think that might be the best approach, but I do not really like it. I think the view should be able to point to that one command, and let the controller register itself to it. I feel the registermethod could be overloaded with a 'Source' filter: Controller A could register itself like: EmployeeChooserCommands.ChooseEmployee.RegisterCommand(chooseEmployeeCommand, this.View); so that it only get's called when the source of the command is actually the view it is interested in.

At this point I find myself just creating routeduicommands and in my controller, registering a commandbinding on its view to handle them. Is that the correct way for this scenario?


Take a look at ActiveAwareDispatchCommand, the same as Multi Dispatch command but only executes the active view's command
Apr 17, 2008 at 10:16 AM
Edited Apr 17, 2008 at 10:17 AM
@RBoeke thanks for your feedback. @hchau is exactly right, ActiveAwareCompositeCommand (the new name in the recent drop), will address this scenario. In this case you are not invoking multiple commands at any one moment, instead only the command for the active screen will be invoked.

Regards
Glenn
Apr 18, 2008 at 1:36 PM


gblock wrote:
@RBoeke thanks for your feedback. @hchau is exactly right, ActiveAwareCompositeCommand (the new name in the recent drop), will address this scenario. In this case you are not invoking multiple commands at any one moment, instead only the command for the active screen will be invoked.

Regards
Glenn


Okay, I had already found it. But it's great to hear that that was the correct approach.

I have created mainview with a 'choose employee' button and a region (named 'detailregion'). That detailregion get's filled with the chosen employee.
The Detailregion has a Teamleader property with again a button next to it.
I have implemented the IsActive interface on the views by looking at the 'gotfocus' and 'lostfocus' events.

The problem I'm having is: the mainview get's focus when the detailregion has focus, because detailregion is a child.

In other words: what better ways are there to determine which view has focus?