質問

I have a nested set of views as follows:
enter image description here

Each view has a Presenter where:

  • the MainViewPresenter has no knowledge of the views or view presenters ViewA or ViewB
  • ViewA and ViewB are individually managed by their respective presenters and in turn managed by the SplitViewPresenter

I have events that will occur in ViewA which the ViewAPresenter will subscribe to. The SplitViewPresenter can subscribe to the child presenter's events and then bubble those up to the MainViewPresenter. But this seems like a horrible waste of effort simply to bubble up a button click from ViewA.

It seems as though there should be a way to couple some event listener from the MainViewPresenter to ViewA.OnButtonClick.

In this case where the MainViewPresenter has no foreknowledge of what is displayed by other presenters, the Observer/Observable pattern does not seem appropriate. Or maybe there is an implementation using Reactive that would work (Note: .Net 4.0 however)

Would a delegate be the way to go? I know that each event subscription on ViewA might require a different delegate which is fine. In this particular instance, the button click will have actions that need to be performed:

  • update the database with new information
  • add the new model created by ViewA to the tree view in the MainView
役に立ちましたか?

解決

I realized that the tree view in the MainView has a collection for the tree nodes. This collection was already raising CollectionChanged events to which the MainViewPresenter is subscribed.

The ViewAPresenter has a reference to this collection and simply adds the saved model to the collection. In turn the MainViewPresenter is notified and the proper node is added.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top