I usually Hook the Closing event in the Window code-behind and then, with a dedicated Interface, access the ViewModel from the DataContext... Something like:
public partial class MainWindow
{
public MainWindow() => Closing += OnClosing;
private void OnClosing(object sender, CancelEventArgs e)
=> e.Cancel = ((IOnClosing)DataContext).Closing();
There's only a couple of lines of code. (Yes, cast checking not included for this example)
But if you're looking for a cleaner solution to work with a command, here is one:
Behavior to support Window Closing in WPF[
^]
Both solutions are valid.