0

I have my PRISM application set up on a MVP pattern and we display modal windows through custom RegionManager. The problem i face right now is when the users close the Modal Window using an Alt+F4! The View closes but the Cancel button logic is never executed, which is a bug!

So I need to draft a way to invoke the Cancel button of the view when an Alt + F4 is issued.

Having a input key binding for Alt+F4 helps me trap the event in the View. but the problem is invoking the Cancel button of the View, in a easy way. is there any way i could easily find the cancel and Accept buttons in WPF View?

Any help is appreciated. thanks!

ioWint
  • 1,609
  • 3
  • 16
  • 34

1 Answers1

2

Since there a several ways to close a window (Alt+F4, close button, Cancel or Accept buttons), you shouldn't put the closing logic in the code of the buttons, because it will not always be executed. Instead, put your closing logic in the Closing or Closed event. In your Cancel button, just set the DialogResult to false (true in the Accept button), it will close the window and trigger the Closing and Closed events.

Thomas Levesque
  • 286,951
  • 70
  • 623
  • 758
  • the View's content is hosted in a Window. As you might know PRISM doesnt have any out of the box support for Modal windows. So presently even if i set DialogResult of the window to true/false The View will not be notified of any thing. it will just vanish from the Screen with out invoking any of the cancel flow path. I know there is an UserControl.Unloaded event, but having logic in it would be too late in case we need to cancel the closing based on a message prompt. – ioWint Nov 14 '11 at 22:37
  • @ioWint, sorry I don't know about PRISM, I assumed your view was a window. But I suspect PRISM provides a cleaner way to do what you want than simulating a click on a button... – Thomas Levesque Nov 15 '11 at 08:37