简体   繁体   中英

Prevent ShowDialog from closing the window in WPF

I have a WPF window myWindow , which I open using myWindow.ShowDialog() ?? true myWindow.ShowDialog() ?? true and listen to the DialogResult ( DialogResult = true ) to execute some code.

When I set it to either true or false , the window is disposed, is there a way I can prevent this window from closing while also getting the DialogResult ? Also, is there a another way I can approach this problem?

What do you want to happen? For example:

You might want a modal dialog (so users can't interact with the rest of the UI while it is visible) but you want code to run in the main program in response to some user action in the dialog. In this case, add events to your dialog that the main program can respond to.

Or you might actually want a modeless dialog, which lets users interact with the rest of the program without completing the dialog. In this case, don't use ShowWindow , just show an owned window.

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