PreivewClose and Close Events - MVVM

3 posts, 0 answers
  1. crazy05
    crazy05 avatar
    74 posts
    Member since:
    Sep 2014

    Posted 04 Jun 2015 Link to this post

    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 ?

  2. crazy05
    crazy05 avatar
    74 posts
    Member since:
    Sep 2014

    Posted 04 Jun 2015 Link to this post

    Here are my interaction trigger.

                        <i:EventTrigger EventName="PreviewClose">
                            <cmd:EventToCommand Command="{Binding PreviewCloseCommand}" CommandParameter="{Binding ElementName=ContentContainer}" />
                        <i:EventTrigger EventName="Close">
                            <cmd:EventToCommand Command="{Binding CloseCommand}" CommandParameter="{Binding ElementName=ContentContainer}" />

  3. Vladi
    Vladi avatar
    749 posts

    Posted 09 Jun 2015 Link to this post

    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.

    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
Back to Top