我是第一次实施MVP模式。我的应用程序是一个向导。只有一个表单,并且嵌入了多个用户控件。 每个控件都是一个视图,每个视图都有一个演示者。我正在尝试实现被动MVP模式。演示者负责处理所有操作并更新视图。
问题是传递UI实体。我想将用户输入从第一个视图传递到第二个视图,因为第二个视图需要对其进行处理。
所有视图都在Win Form上实例化。
任何帮助都将受到高度赞赏。
此致
答案 0 :(得分:0)
您可以创建一个包含所需实体的类。 当你打开一个新窗口时,你在构造函数中传递了这个类,瞧,你的数据已被传输。
答案 1 :(得分:0)
我正在考虑以下情况: 创建一个用于保存不同视图的枚举
public enum Views{
First,Second, Manager,Third,
}
为您的buttonstate创建一个可枚举
public enum ButtonState{Start,Next,Cancel,Back,}
创建将保存所有数据的类
public class MyData
{
//properties here
//Also have a default constructor
public MyData()
{
}
}
然后在您的表单中使用这些新项目:
Public Views MyViewState { get; set;}
Public ButtonState MyButtonState { get; set;}
Public MyData dataclass { get; set;}
Public Form1()
{
InitializeComponent();
MyViewState = Views.First;
MyButtonState = ButtonState.Start;
dataclass = new MyData(); //mostly at startup your class data is empty ...
ControlViews();
}
Public void ControlViews()
{
//Based on your Buttons you will do what each form is asked to do:
switch(MyButtonState)
{
case ButtonState.Start:
//Since this is your startup: you only need to show your next view and replace you MyViewState
MyViewState = Views.First;
///code for showing your view
Break;
case ButtonState.Next:
//Since this time you probably filled in data you need to know in which MyViewState you are
Switch (MyViewState)
{
Case Views.First:
//You want to keep your data
///Code for placing data into your dataclass
//After replacing the code, you then need to do some calculations and open the next view
///Code for calculations and placing this data in the form
///Code for opening the second view
MyViewState = Views.Second;
Break;
// you then need to do this for each MyViewState
}
Break;
}
}
使用这种系统的好处是,您的所有数据都保留在课堂中,您只需显示/关闭您的视图。
这是我如何反击这一点的方式。