Saturday, October 15, 2016

How to make modal dialog in WPF?

Showing your window using the ShowDialog method:

 // set Owner property
w.Owner = Window.GetWindow(this);

// or
w.Owner = this;

// or
w.Owner = Application.Current.MainWindow;

// or
w.Owner = (Window)PresentationSource.FromVisual(this).RootVisual;

w.ShowDialog();

Note: Don't forget to set the Owner property on the dialog window. Otherwise, the user will get weird behavior when Alt+Tabbing, etc.

Reference:

http://stackoverflow.com/questions/499294/how-do-make-modal-dialog-in-wpf

No comments: