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;


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


No comments: