I have Cancel Command in ViewModel.
Which is bound to a cannel Button in child View.
When i press cancel button it will clear all my unsaved data in viewModel.
Additionally i have to close the current instance of child window.-This is where I am stuck.
I am using MVVM.
An alternative to using an event is an attached property that goes on the view. The property changed handler will find the parent window of the view and close it as soon as a particular value is recognized.
And the view's XAML looks something like...
I use the following pattern.
I have a base class for my ViewModel
which is implementing this interface
And a window base class for my View I want to show and close via a ViewModel
Your ViewModel which is the DataContext from your View you want to show as dialog has to inherit from
ClosableViewModel
and your dialog has to inherit fromClosableWindow
. When you want to close your View from the ViewModel you just have to call theCloseView
method.