How do I open a window as a modal dialog in MonoMac using C#?

c#, macos, monomac

Solution

I spent almost three hours trying to figure this out before posting the question, but of course I found the solution right after asking.

It looks like I need to use the NSApplication object:

NSApplication.SharedApplication.RunModalForWindow(ewc.Window);

Problem

I am developing a Cocoa application with MonoMac (C#). I have a class `MyWindowController` that inherits `MonoMac.AppKit.NSWindowController`, and open a new instance of this window like this: ``` MyWindowController mwc = new MyWindowController(); mwc.Window.MakeKeyAndOrderFront(this); ``` But how do I open it as a modal dialog? It is imperative that nothing else in my application is executed while the dialog is open, so I cannot use a window sheet (which only blocks the current window). And I can't find anything else that seems to do what I want on my controller. On Windows, I would have done this simply by calling: ``` mwc.ShowDialog(); ``` So what I want is the MonoMac equivalent of `ShowDialog()`, I believe.

Original source