Asim Sajjad
Asim Sajjad

Reputation: 2534

Close View From viewModel using MVVM or without ViewModel

Is there any way to close the view when user click on the close button (X) on the view or I just want to know something like ApplicationsCommand.close don't want to use IRequestCloseViewModel interface. thanks a lot

Upvotes: 0

Views: 777

Answers (1)

Ray Burns
Ray Burns

Reputation: 62919

Yes, there is an ApplicationCommands.Close and it is used just like you suggest: Anywhere you have a close button, bind it to ApplicationCommands.Close like this:

<Button Content="{StaticResource CloseX}" Command="Close" />

Now in your base class you use for your views, register a event handler for this command and when it fires, remove the view from its parent or otherwise close the view. The details of how to do this depend on how you have your view windows managed. If each view is an independent window, just close the window. But if there is a view manager that manages layout, remove the view from it.

Upvotes: 2

Related Questions