user1427026
user1427026

Reputation: 879

Prevent ShowDialog from closing the window in WPF

I have a WPF window myWindow, which I open using 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?

Upvotes: 1

Views: 1032

Answers (1)

arx
arx

Reputation: 16896

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.

Upvotes: 1

Related Questions