I'm developing an WPF app using MVVMLight, and in my main view I have the following:
<i:Interaction.Triggers>
<i:EventTrigger EventName="Closing">
<command:EventToCommand Command="{Binding WindowClosing}" PassEventArgsToCommand="True"/>
</i:EventTrigger>
</i:Interaction.Triggers>
Which I bind to the following in my view model:
public ICommand WindowClosingCommand { get; private set; }
public MainViewModel()
{
WindowClosingCommand = new RelayCommand<CancelEventArgs>((args) => ExecuteWindowClosingCommand(args));
}
public void ExecuteWindowClosingCommand(CancelEventArgs e)
{
if (UserSaysNo())
{
e.Cancel = true;
}
}
This all works great, and I can display a dialog prompt which allows the user to cancel if required. The problem I have is: how do I bind a 'File->Exit' main menu command to this?
Thanks in advance! Chris