Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you navigate between views in MVP using C# WinForms?

As I understand, when we use MVP we move all presentation logic to the Presenter. But we don't want to let the Presenter know about view implementation, so how can we navigate to another screen in the application? How do you manage application flow on your real application?

like image 972
Samnang Avatar asked Apr 02 '09 01:04

Samnang


3 Answers

I assume that you mean another screen that has its own MVP-pair?

I was thinking about that case this morning, my solution will probably be that there is a Coordinator knows the Presenter and the MVP-pair that needs to be opened. That one opens the new presenter+view and, when finished, optionally calls a method on the first presenter with the results.

In that way, the first MVP doesn't have to know anything about the new screen, they only fire an event. The logic for opening the second window and communicating back is entirely contained in the Coordinator.

like image 27
Lennaert Avatar answered Nov 14 '22 00:11

Lennaert


Using some navigator interface, for example:

interface INavigator
{
    void MoveTo (string screenName);
    void MoveTo (string screenName, NavigationParameters parameters);
}

Each presenter would then have an instance of this navigator passed in the constructor. This way the navigation is decoupled both from the presenter and from individual views.

You can have the mapping between screen names and actual Form classes defined in a configuration.

like image 156
Igor Brejc Avatar answered Nov 14 '22 02:11

Igor Brejc


It's a Method on the view. So you would have an abstract method, like ShowCustomerForm(), for example, and the implementation for WinForms would be CustomerForm.Show (or whatever it is in WinForms) and in WebForms it would be Response.Redirict(CustomerForm.aspx).

like image 24
Charles Graham Avatar answered Nov 14 '22 02:11

Charles Graham