You are getting the error you mentioned because you're trying to bind a command to an event ("Closing" and "Closed" are both events) which, instead, expects an event handler.
There are ways, as shown in this thread, to declare an event handler that invokes a command entirely in XAML using bindings and this would be the best solution in order to adhere to the MVVM pattern.
Another solution involves handling events such as Closed or Closing directly in your code-behind and invoke from there your ViewModel's commands. This is somehow simpler but requires your View to have a tight dependency from your ViewModel so it is not the best solution in terms of MVVM compliance. You can, however, loose this dependency by using interfaces if you want to strictly adhere to MVVM.
Here's an example
// MyApp\ViewModel\MyViewModel.cs
public class MyViewModel : IClose
{
public ICommand CloseCommand { get; }
// ...
}
// MyApp\Abstractions\IClose.cs
public interface IClose
{
ICommand CloseCommand { get; }
}
// MyApp\View\MyView.xaml.cs
public partial class MyView
{
public MyView()
{
InitializeComponent();
}
protected void OnClosing(object sender, EventArgs e)
{
var close = this.BindingContext as IClose;
if (close is null) return;
close.CloseCommand.Execute(null);
}
}
With MyApp\View\MyView.xaml
being
<Window x:Class="MyApp.View.MyView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:vm="clr-namespace:MyApp.ViewModel"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Closing="OnClosing">
<Window.DataContext>
<vm:MyViewModel/>
</Window.DataContext>
</Window>