如何在winforms mvp模式中实现usercontrol? [英] how Implement usercontrol in winforms mvp pattern?
问题描述
我想实现MVP模式.我有一个带有一些文本框的用户控件,当我将其放入表单时,我从usercontrol调用一个方法并填充文本框.但是在mvp模式下,我不知道如何访问usercontrol1.fill()
.你有一个可以帮助我的例子吗?
I want to Implement MVP pattern. I have a user control that has some Textboxes and when I put it in form I call a method from usercontrol and fill textboxes. But in mvp pattern I don't know how I can access to usercontrol1.fill()
. Do you have an example that could help me?
推荐答案
以下是该模式的示例实现.演示者仅知道具有show方法的界面.演示者将其调用,但是唯一的表单(又称视图")实现了表单的显示方式.
Here is an example implementation of the pattern. The Presenter only knows about the interface having a show method. The Presenter calls it, but the only the form (aka View) implements how the form should be displayed.
public interface IMyFormView {
void Show();
}
public class MyForm : IMyFormView {
public MyForm() {
var presenter = new MyFormPresenter(this);
presenter.Init();
}
public void Show() {
usercontrol1.fill();
}
}
public class MyFormPresenter
{
private IMyView _view;
public MyFormPresenter(IMyView view) {
_view = view;
}
public void Init() {
_view.Show();
}
}
如果需要将数据传递到视图中,则可以通过Show
方法传递视图模型或在视图上设置自定义属性.
If you need to pass data into the view, then you can pass a view model through the Show
-method or set custom Properties on the view.
这篇关于如何在winforms mvp模式中实现usercontrol?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!