Reputation: 77
I have a modal window in a WPF application which contains a button. After clicking the button, the modal window is closing. How can I force buttons not to close the window? Of course one button should close the window, but not this one. :)
Upvotes: 1
Views: 529
Reputation: 115
Another possible solution that caused my application to close:
In my Menu the MenuItem "File" had a Item "Close". On accident I set the CloseButton_Click-Event to "File". That caused my MenuItem "Save" to always close my application.
Upvotes: 0
Reputation: 244732
Make sure that you're not setting the DialogResult
property of the window in the Click
event handler methods for the buttons.
Setting that property causes the modal dialog to end, causing the window to automatically close and return that value to the ShowDialog
method. You should not set this property until you are ready to close the dialog.
Upvotes: 0
Reputation: 528
Do you have IsCancel or IsDefault set on that button? If so, remove that.
Upvotes: 2