This is a migrated thread and some comments may be shown as answers.

PreivewClose and Close Events - MVVM

5 Answers 866 Views
Docking
This is a migrated thread and some comments may be shown as answers.
crazy05
Top achievements
Rank 1
crazy05 asked on 04 Jun 2015, 07:02 PM

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

Sort by
0
crazy05
Top achievements
Rank 1
answered on 04 Jun 2015, 07:07 PM

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>

0
Vladi
Telerik team
answered on 09 Jun 2015, 10:22 AM
Hi Ram,

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
herb
Top achievements
Rank 1
Veteran
Iron
answered on 10 Dec 2019, 05:13 PM

Do you have a sample that compiles to step through? (DockingCancelClose.zip)

<Window x:Class="DockingCancelClose.MainWindow"
        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

0
Dinko | Tech Support Engineer
Telerik team
answered on 13 Dec 2019, 09:04 AM

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

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
herb
Top achievements
Rank 1
Veteran
Iron
answered on 13 Dec 2019, 03:21 PM
Thank you Dinko, that works.
Tags
Docking
Asked by
crazy05
Top achievements
Rank 1
Answers by
crazy05
Top achievements
Rank 1
Vladi
Telerik team
herb
Top achievements
Rank 1
Veteran
Iron
Dinko | Tech Support Engineer
Telerik team
Share this question
or