我有一个应用程序,其中一部分包含一组循环中的 wpf 窗口,发送一个业务对象以对模型进行更改。像这样的东西(不是真正的代码):
class Window1 {
BusinessObject obj;
public Window1 (BusinessObject obj){
this.obj = obj;
}
/* Things showing obj info and modifying it. */
public void on_Button_Next_Click(object sender, EventArgs args){
new Window2(obj).Show();
this.close();
}
}
class Window2 {
BusinessObject obj;
public Window2 (BusinessObject obj){
this.obj = obj;
}
/* Things showing obj info and modifying it. */
public void on_Button_Next_Click(object sender, EventArgs args){
new Window3(obj).Show();
this.close();
}
}
class Window3 {
BusinessObject obj;
public Window3 (BusinessObject obj){
this.obj = obj;
}
/* Things showing obj info and modifying it. */
public void on_Button_Next_Click(object sender, EventArgs args){
if (!obj.Finished) {
new Window1(obj).Show();
this.close();
}
}
}
有了新的变化,不再总是 W1 -> W2 -> W3 -> W1,取决于业务对象的信息,每次迭代有 4 种不同的路径:W1 -> W2 -> W3 -> W2 -> W1 ,或 W1 -> W2 -> W3 -> W1 -> W2 -> W1,所以我需要为每个窗口设置一个状态。
class Window1 {
BusinessObject obj;
public Window1 (BusinessObject obj, int path, int repetition){
this.obj = obj;
}
/* Things showing obj info and modifying it. */
public void on_Button_Next_Click(object sender, EventArgs args){
if (path == 0) {
new Window2(obj).Show();
this.close();
}
if (path == 1 && repetition = 0){
new Window2(obj, path, 0).Show();
this.close();
}
else {
new Window3(obj, path, 1).Show();
this.close();
}
}
}
是否可以使用窗口管理器来控制窗口而不是这样做?像这样
while (true) {
new Window1(obj).Show();
wait(Window1);
new Window2(obj).Show();
wait(Window2);
if (obj.Condition1){
new Window3(obj).Show();
} else {
new Window1(obj).Show();
wait(Window1);
new Window3(obj).Show();
}
}
如果可能的话,会是一个不好的做法吗?