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

As I understand it, when we use MVP, we move all presentation logic to Presenter. But we don’t want the speaker to know about the implementation of the view, so how can we go to another screen of the application? How to control application flow on your real application?

+6
c # design-patterns mvp winforms
source share
4 answers

Using some navigator interface, for example:

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

Each leader should then have an instance of this navigator passed in the constructor. Thus, navigation is separated from both the host and individual views.

You may have a mapping between screen names and the actual form classes defined in the configuration.

+3
source share

This is a seemingly method. This way you will have an abstract method like ShowCustomerForm (), and the implementation for WinForms will be CustomerForm.Show (or whatever it is in WinForms), and in WebForms it will be Response.Redirict (CustomerForm.aspx).

+1
source share

I assume you mean another screen with its own MVP pair?

I thought about this case this morning, my decision will probably be that the Coordinator knows the Lead and the MVP pair to open. This opens a new presenter + view and, at the end, does not necessarily call the method on the first presenter with the results.

Thus, the first MVP does not need to know anything about the new screen, it only fires the event. The logic for opening the second window and transferring it entirely is contained in the Coordinator.

+1
source share

We do this using what Lennaert calls the coordinator (we call this the workflow controller). I came from Java web development and the idea was a form of ApplicactionController. I ran into some problems with this, the workflow controller runs the command. Each command represents a workflow or a series of related steps (thus, the name of the workflow). The flowcontroller handles navigation between teams, and the flow controller has a navigator that moves between steps. At each step there is a finishing event (to which the host connects) and the NextStep method, which we use to proceed to the next step. Our worflow manager is closely related to the menu, so we can navigate between different workflows. The steps establish a connection between the presentation and the presenters. We don’t have any configuration, and we installed logic that sets the next step to be executed in a method called NextStep. It is in production, but I am not very happy with it. Too many details to enter here. I thought about turning something more than an event. We use the message bus to execute all of our other messages, and I would like to switch to this to move between screens. I do not know if it will be useful or not. our screens mostly consist of sequential workflows.

0
source share

All Articles