简体   繁体   中英

WPF equivalent of Form.ShowDialog(IWin32Window)

In WPF we have Window.ShowDialog() which allows showing a modal dialog box.

In WinForms there is similar functionality but it also has an overload Form.ShowDialog(IWin32Window) which allows an IWin32Window owner to be passed in. That way the new dialog is not modal, and always maintains a z-order directly above its owner.

How would I get this same functionality using WPF?

Use the Owner property on a Window.

To expand on @Jonathan.Peppers's answer:

Say you had a Window you named FooWindow , and in BarWindow.cs you wanted to create and execute an instance. You can create a modal version of FooWindow as simple as this:

new FooWindow(){ Owner = this }.ShowDialog();

That would assume you didn't need a reference to you instance, obviously, but you get the idea?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM