MVVM - exit confirmation

I am trying to learn MVVM, but still do not understand.

I currently have this event handler:

private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
    if (MessageBox.Show("Are you sure you want to close this application?", "Close??", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
    {
        e.Cancel = true;
    }
}

Very easy. However, I would like to apply the MVVM pattern in this application.

I am wondering if I should put this logic in the ViewModel, and not directly in the view code? If so, how should I do this?

thank

+5
source share
1 answer

You can use your own ViewsService, which you can use in the ViewModel and interact with the View. For example, you can write the ViewsService.CloseActiveWindow () method. In this case, you do not need to interact with the View directly from the ViewModel, but through the service class.

: /. ViewModel , View . , .

0

All Articles