1

I have a WPF window that is opened when the user clicks on one of the toolbar's buttons of my WPF control.

The user has to enter some data and then press the 'OK' button. When the 'OK' button is pressed I process the data, and if the processing was successful I want to close the window, otherwise I want to display a message, but leave the window opened.

How do I control closing / not closing the window from my ViewModel?

Holly
  • 81
  • 1
  • 9

1 Answers1

0

You can define a property IsProcessingSuccessful on the ViewModel that you set to true/false at the end of the execution. When the processing is done, the View checks the value of this property and acts accordingly: close the window or leave it open.

Andy
  • 3,631
  • 2
  • 23
  • 32
  • I don't really understand what to do with this new property? To what do I have to bind this property in order for this to work? – Holly Oct 13 '13 at 18:00
  • You can set an event on the ViewModel that notifies the View that the processing is over(see here: http://stackoverflow.com/a/7671711/339702 ). When the event is fired, you check the value of the `IsProcessingSuccessful` property of the ViewModel, that I described – Andy Oct 14 '13 at 11:23