使用MVP加载子视图

Nat*_*n W 8 c# mvp winforms

在过去的几天里,我一直在使用winforms玩MVP模式,只有一件事我不知道该怎么做.如何从另一个视图创建子窗体.这是一个有效的选择吗?

 public class MyForm : IMainFormView
    {
        private MainFormPresenter pres;
        public MyForm() { pres = new MainFormPresenter(this); }

        //Event from interface.
        public event EventHandler<EventArgs> LoadSecondForm;

        public void SomeButtonClick()
        {
            LoadSecondForm(this, EventArgs.Empty);
        }
    }

    public class MainFormPresenter
    {
        private IMainFormView mView;

        public MainFormPresenter(IMainFormView view) {
            this.mView = view;
            this.Initialize();
        }

        private void Initialize() {
            this.mView.LoadSecondForm += new EventHandler<EventArgs>(mView_LoadSecondForm);
        }


        private void mView_LoadSecondForm(object sender, EventArgs e) {
            SecondForm newform = new SecondForm(); //Second form has its own Presenter.
            newform.Load(); // Load the form and raise the events on its presenter.
        }
    }
Run Code Online (Sandbox Code Playgroud)

我主要关注的是如何使用这种模式加载子表单,以及如何将第一页的ID传递给子表单.

谢谢.

Ken*_*ran 8

http://www.rickardnilsson.net/post/The-Humble-dialog-v2.aspx

上面的链接是我见过的最接近这个的链接.解决这个问题的大多数尝试都有待改进.