When the DeleteEvent is called by a Gtk# window, how can I prevent the window from closing?

gtk#

Solution

You need to set the DeleteEventArgs.RetVal to true, not false. From the relevant Mono documentation:

To keep a `Gtk.Window` from closing, set `Gtk.DeleteEventHandler`'s `Gtk.DeleteEventArgs.RetVal` to `true`.

Problem

When the window closes, the user is asked to save the file that they edited. They should also have an option to cancel quitting the application. In WPF I can set the CancelEventArgs.Cancel property to true to do this. Is there an equivalent/workaround in Gtk#?

Original source