2

When user clicks on X, I want to check whether there are any unsaved changes in the page. I have isSaved Property which tells me that.

Now, if there are any unsaved changes, I want to show Alert window(which is in place) to confirm by user to close pane or not.

If user says Yes, I want to close. If not I dont want to close.

How can I implement this in MVVM ? I understand PreviewClose in triggering first. If there are unsaved changes, How can I stop closing the pane ?

Here are my interaction trigger.

 <i:Interaction.Triggers>
                <i:EventTrigger EventName="PreviewClose">
                    <cmd:EventToCommand Command="{Binding PreviewCloseCommand}" CommandParameter="{Binding ElementName=ContentContainer}" />
                </i:EventTrigger>
                <i:EventTrigger EventName="Close">
                    <cmd:EventToCommand Command="{Binding CloseCommand}" CommandParameter="{Binding ElementName=ContentContainer}" />
                </i:EventTrigger>
            </i:Interaction.Triggers>
Chatra
  • 2,989
  • 7
  • 40
  • 73
  • See http://stackoverflow.com/questions/3683450/handling-the-window-closing-event-with-wpf-mvvm-light-toolkit – Contango Jun 04 '15 at 22:42

1 Answers1

0

For a couple of solutions, see Handling the window closing event with WPF / MVVM Light Toolkit.

As for cancelling the window closing, you can update CancelEventArgs to cancel the event.

Community
  • 1
  • 1
Contango
  • 76,540
  • 58
  • 260
  • 305