I've tried a few solutions such as binding the closing event to a command, which worked to the point where it would ask the user if they were sure they wanted to cancel but no matter what the user selected the command was returned and the cancel was still processed.
I've used blend to create an event trigger which using CallMethodAction to call a Close method in my view model which I can't seem to stop from overall closing the window.
Is it possible without using MVVM light to cancel the closing event based on a users selection?
Examples of code I've tried;
Using blend event triggers:
<i:Interaction.Triggers>
<i:EventTrigger EventName="Closing">
<ci:CallMethodAction MethodName="CloseView" />
</i:EventTrigger>
</i:Interaction.Triggers>
The code for CloseView is just a virtual void on a base class to my viewmodel but I can't find any way to stop the event processing.
And the other way, which I kind of want to avoid is the answer here How to cancel window closing in MVVM WPF application.
This involves putting the cancel command in the code behind for the view, the datacontext of my view is set to the viewmodel but when using the code
<Window
...
x:Class="MyApp.MyView"
Closing="OnClosing"
...
/>
</Window>
I get an XMLParse exception that it can't find the OnClosing method, which is presumably because it's looking into the code behind for the view.
Is there another way to do this without putting the OnClosing method into my code behind?