When user clicks on X, I want to check whether there are any unsaved changes in the page.
I have isNotSaved 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 Pure MVVM ?
5 Answers, 1 is accepted
![](/forums/images/avatarimages/default.gif)
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>
Thank you for contacting us.
In the RadDocking control when a RadPane or a RadPaneGroup is closed via its close button the PreviewClose and Close events of the control are raised. The PreviewClose can be used to implement the closing verification and if the pane which triggered the event should not be closed you simply need to handle the event. In order to achieve the desired behavior in a MVVM friendly approach you could take advantage of our EventToCommandBehavior.
All you need to do is:
- Create a custom ICommand in your ViewModel that will be used when the PreviewClose event of the RadDocking is triggered
- Using the EventToCommandBehavior's EventBindings add a binding for the PreviewClose event and set its Command to the custom command in your ViewModel
- Set the PassEventArgsToCommand of the EventBinding to True
- Finally in the Executed method of the custom Command add implementation that will open a verification dialog (for example RadWindow.Confirm()) and use its returned value to determine if the event should be handled or not
I created and attached a sample project of the described approach for you, hope this is helpful.
Regards,
Vladi
Telerik
![](/forums/images/avatarimages/default.gif)
Do you have a sample that compiles to step through? (DockingCancelClose.zip)
<
Window
x:Class
=
"DockingCancelClose.MainWindow"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
xmlns:local
=
"clr-namespace:DockingCancelClose"
Title
=
"MainWindow"
Height
=
"500"
Width
=
"900"
>
<
Window.DataContext
>
<
local:ViewModel
/> <<<<this is where the error points to.
</
Window.DataContext
>
getting this message in VS:
Severity Code Description Project File Line Suppression State
Error XDG0008 The name "ViewModel" does not exist in the namespace "clr-namespace:DockingCancelClose". DockingCancelClose MainWindow.xaml 8
Hello Herb,
I have double-checked the project but such error does not appear on my side. I am re-attaching the sample project with a trial version of our DLLs so you can download it and run it without making any modifications. Give it a try and let me know if this error appear on your side again.
Regards,
Dinko
Progress Telerik
![](/forums/images/avatarimages/default.gif)