开发者

What could be causing my WPF modal window to close after a button is pressed?

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. :)


Do you have IsCancel or IsDefault set on that button? If so, remove that.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜