1
votes

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?

1
You don't. Your View is responsible for form validation. - Khan

1 Answers

0
votes

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.