瀏覽代碼

Fix NewFile modal

Old code is not valid. 1) You can't add event handler in object initializer. 2) ml2 isn't used outside of the method. So you can use local variable.
Pavel Kurkutov 4 年之前
父節點
當前提交
3e46047971
共有 1 個文件被更改,包括 14 次插入10 次删除
  1. 14 10
      StandaloneExample/Program.cs

+ 14 - 10
StandaloneExample/Program.cs

@@ -141,17 +141,21 @@ class Demo {
 
 
 	}
 	}
 
 
-	public static Label ml2;
-
 	static void NewFile ()
 	static void NewFile ()
 	{
 	{
-		var d = new Dialog (
-			"New File", 50, 20,
-			new Button ("Ok", is_default: true) { Clicked = () => { Application.RequestStop (); } },
-			new Button ("Cancel") { Clicked = () => { Application.RequestStop (); } });
-		ml2 = new Label (1, 1, "Mouse Debug Line");
-		d.Add (ml2);
-		Application.Run (d);
+		var okButton = new Button ("Ok", is_default: true);
+                okButton.Clicked += () => { Application.RequestStop (); };
+                var cancelButton = new Button ("Cancel");
+                cancelButton.Clicked += () => { Application.RequestStop (); };
+
+                var d = new Dialog (
+                    "New File", 50, 20,
+                    okButton,
+                    cancelButton);
+
+                var ml2 = new Label (1, 1, "Mouse Debug Line");
+                d.Add (ml2);
+                Application.Run (d);
 	}
 	}
 
 
 	static bool Quit ()
 	static bool Quit ()
@@ -207,4 +211,4 @@ class Demo {
 		top.Add (menu);
 		top.Add (menu);
 		Application.Run ();
 		Application.Run ();
 	}
 	}
-}
+}