How to make modal dialog in WPF?

Alex Baranosky picture Alex Baranosky · Jan 31, 2009 · Viewed 168.3k times · Source

I am writing my first application in WPF and want to have the user input some data on a modal dialog window. Apparently, this is not simple to do in WPF, because the parent window stays fully enabled, and the method that created the new child window doesn't stop and wait for the child window to call Close(). Instead it just keeps going forward. This is not what I want.

How can I get the child window to open, and have the parent window wait for the child to close before the parent window continues executing?

Answer

Yordan Pavlov picture Yordan Pavlov · Jan 31, 2009

Did you try showing your window using the ShowDialog method?

Don't forget to set the Owner property on the dialog window to the main window. This will avoid weird behavior when Alt+Tabbing, etc.