public void RespondOnClosingWithCancel() { // If Respond if called on a CloseRequest, but the close is canceled, the respose call is ignored using (var win = new Dialog()) { bool closeCanceled = false, closeResult1 = false, closeResult2 = false; win.Buttons.Add(new DialogButton(Command.Ok)); win.CloseRequested += HandleCloseRequested; Application.TimeoutInvoke(10, delegate { closeResult1 = win.Close(); Application.TimeoutInvoke(10, delegate { win.CloseRequested -= HandleCloseRequested; closeCanceled = true; closeResult2 = win.Close(); return(false); }); return(false); }); var cmd = win.Run(); Assert.IsTrue(closeCanceled, "Close not canceled"); Assert.IsFalse(closeResult1, "First close should return false"); Assert.IsTrue(closeResult2, "Second close should return true"); Assert.IsNull(cmd); } }
public void RespondOnClosing() { // Respond can be used in a CloseRequest handler to provide a result for the Run method using (var win = new Dialog()) { bool closeResult = false; win.Buttons.Add(new DialogButton(Command.Ok)); win.CloseRequested += delegate(object sender, CloseRequestedEventArgs args) { win.Respond(Command.Apply); }; Application.TimeoutInvoke(10, delegate { closeResult = win.Close(); return(false); }); var cmd = win.Run(); Assert.AreEqual(Command.Apply, cmd); Assert.IsTrue(closeResult); } }
public void Close () { // The Close method can be used to stop running a dialog bool closing = false, closed = false, closeResult = false; using (var win = new Dialog ()) { win.Buttons.Add (new DialogButton (Command.Ok)); win.CloseRequested += delegate(object sender, CloseRequestedEventArgs args) { Assert.IsTrue (args.AllowClose); closing = true; }; win.Closed += (sender, e) => closed = true; Application.TimeoutInvoke (10, delegate { closeResult = win.Close (); return false; }); var cmd = win.Run (); Assert.IsNull (cmd); Assert.IsTrue (closing, "CloseRequested event not fired"); Assert.IsTrue (closed, "Window not closed"); Assert.IsTrue (closeResult, "Window not closed"); } }
public void Close() { // The Close method can be used to stop running a dialog bool closing = false, closed = false, closeResult = false; using (var win = new Dialog()) { win.Buttons.Add(new DialogButton(Command.Ok)); win.CloseRequested += delegate(object sender, CloseRequestedEventArgs args) { Assert.IsTrue(args.AllowClose); closing = true; }; win.Closed += (sender, e) => closed = true; Application.TimeoutInvoke(10, delegate { closeResult = win.Close(); return(false); }); var cmd = win.Run(); Assert.IsNull(cmd); Assert.IsTrue(closing, "CloseRequested event not fired"); Assert.IsTrue(closed, "Window not closed"); Assert.IsTrue(closeResult, "Window not closed"); } }
public void RespondOnClosing () { // Respond can be used in a CloseRequest handler to provide a result for the Run method using (var win = new Dialog ()) { bool closeResult = false; win.Buttons.Add (new DialogButton (Command.Ok)); win.CloseRequested += delegate(object sender, CloseRequestedEventArgs args) { win.Respond (Command.Apply); }; Application.TimeoutInvoke (10, delegate { closeResult = win.Close (); return false; }); var cmd = win.Run (); Assert.AreEqual (Command.Apply, cmd); Assert.IsTrue (closeResult); } }
public void RespondOnClosingWithCancel () { // If Respond if called on a CloseRequest, but the close is canceled, the respose call is ignored using (var win = new Dialog ()) { bool closeCanceled = false, closeResult1 = false, closeResult2 = false; win.Buttons.Add (new DialogButton (Command.Ok)); win.CloseRequested += HandleCloseRequested; Application.TimeoutInvoke (10, delegate { closeResult1 = win.Close (); Application.TimeoutInvoke (10, delegate { win.CloseRequested -= HandleCloseRequested; closeCanceled = true; closeResult2 = win.Close (); return false; }); return false; }); var cmd = win.Run (); Assert.IsTrue (closeCanceled, "Close not canceled"); Assert.IsFalse (closeResult1, "First close should return false"); Assert.IsTrue (closeResult2, "Second close should return true"); Assert.IsNull (cmd); } }