is there a way to handle the window close button ie \"X\" in the top right corner in the viewmodel by binding to a command? or overriding the window.close command so that cl
There are several methods for this. I have pointed out two methods below.
You can use attached commands to bind the close button in your view model.
You can use Below code
Xaml:
NOTE: Add System.Windows.Interactivity reference
View Model
private ICommand closeWindowCommand;
public ICommand CloseWindowCommand
{
get
{
if (closeWindowCommand == null)
{
closeWindowCommand = new RelayCommand(param => this.CloseWindow(), null);
}
return closeWindowCommand;
}
}
private void CloseWindow()
{
//Do your operations
}
This is my RelayCommand class.
public class RelayCommand : ICommand
{
///
/// Initializes a new instance of the class.
///
/// The execute.
public RelayCommand(Action