'Prism (WPF) - CancelEventArgs.Cancel already set to true

I'm dealing with a really frustrating issue whilst attempting to use Prism's command actions to cancel closing a shell based on a simple yes / no decision dialog.

When I close the shell, it immediately closes and the eventArgs.Cancel is set to true.

This makes no sense to me as I'm hooking into Closing not Closed and if Cancel is already set to true the shell shouldn't close?!

Interaction triggers in the view:

<i:Interaction.Triggers>
    <i:EventTrigger EventName="Closing">
        <prism:InvokeCommandAction Command="{Binding Close}" />
    </i:EventTrigger>
</i:Interaction.Triggers>

ICommand Property in VM

public ICommand Close { get; set; }

Hooking up in constructor

this.Close = new Prism.Commands.DelegateCommand<CancelEventArgs> (this.HandleClose);

Handler Method

private void HandleClose (CancelEventArgs eventArgs)
    {          
        log.LogDebug ($"Close requested");

        bool shouldCancel = CommonWindows.ShowConfirmationDialog ("Do you want to cancel before closing?", "CancelBeforeClose");

        if ( shouldCancel )
        {
            eventArgs.Cancel = true;
            return;
        }
            
        log.LogDebug ($"Closing window - {this.shellItem.ShellName} [{this.Title}]");

        this.eventAggregator.GetEvent<CloseShellEvent> ().Publish (this.shellItem.ShellName);
        this.isShellClosed = true;
    }

Debugging handle method

I'd appreciate any pointers I can get, cheers in advance!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source