wpf - How a command from main window be handled in a usercontrol view model -


In my application I have many user controls in the window. These user controls need to communicate with each other

  • The main window gets the command and
  • User controls handle B command.

    My problem is how can the main window command fire, which can be controlled in the VIEW model of User Control B?

    Update:

    Solution: A Global Routing Comand for Communication for B from the Main Window and a Global Routine Comand for Communication from A to Main Window. Thanks for the responses.

    question mvvm has not been tagged (yet), but I Believe it since you mention a ViewModel, from the beginning, assume that the ViewModels handle handle is not in control, if any control wants to respond to the executed command, then a suitable command is executed Expose the event that the control (see) can attach to a handler.

    However one unknown is unknown that I can not assume indiscriminately:

    Do you take it that the user A and B exists at the same time? If so, then a very simple and low-tech solution would be to maintain the reference on both levels (possibly for the window View Modal?) And "Bubbles" on both methods, The dispatch of B will occur. If not (in which case control B is not present), then what is the desired behavior?

    With the information you have given, I suggest using your MVVM event aggregator / intermediate pattern. For example, in the prism; MVVM is light; e.t.c.

  • Comments