We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

prevent viewmodel within document container from closing

I'm displaying multiple viewmodels using a DockingManager. These viewmodels are added as documents. When the user shuts down one of these tabs (documents) I want to popup a modal dialog to prompt them to save their changes, but they should also be able to cancel and return to the active viewmodel. 
Binding an ICommand to DocumentContainerDocumentClosingCommand seems like the perfect method to do this. My question is what do I do within the handler method associated with the ICommand to stop the view closing if the users selects "Cancel" in the modal dialog.
Thanks.

7 Replies

SM Subashini Mahendran Syncfusion Team July 20, 2017 01:02 PM UTC

Hi Zeljko Lazic,

Thank you for contacting Syncfusion support.

We have checked your query "Prevent ViewModel within DocumentContainer from closing". We cannot use "DocumentContainerDocumentClosingCommand" to stop the ViewModel closing while selecting the "Cancel" option in modal dialog by execute closing with the help of Command . But we can achieve your requirement by write the Behaviors for DocumentContainer and cancel the Closing event of DocumentContainer based on the result of ModalDialog. We have prepared a sample based on your requirement. Please download the sample from the below link.

Sample: DocumentContainer_Sample
 
If we misunderstood your requirement, Can you please provide us more information regarding the requirement. This would help us to proceed further.

Regards,
Subashini M.
 



ZL Zeljko Lazic July 20, 2017 01:25 PM UTC

Thanks for your quick reply.

I'm not actually using a DocumentContainer. My application closely resembles the DockingManger from the syncfusion examples...

\Essential Studio Samples\15.2.0.40\WPF\Showcase\DockingManagerMVVMCaliburnDemo\CS

In this particular example, there are 2 view models added with "DockState.Document enum".

MainWindowXAMLViewModel mainwindowxaml = new MainWindowXAMLViewModel() { Header = "MainWindow.xaml", State = DockState.Document };


MainWindowCSViewModel mainwindowcs = new MainWindowCSViewModel() { Header = "MainWindow.xaml.cs", State = DockState.Document };


So in my application i'm showing a dialog to prompt the user to save their edits. I've attached a sample application where i'm attempting to intercept the closing of either of these viewmodels (MainWindowXAMLViewModel, MainWindowCSViewModel).



Attachment: DockingManagerMVVMCaliburnDemo_4ee0717a.zip


SM Subashini Mahendran Syncfusion Team July 21, 2017 12:10 PM UTC

Hi Zeljko Lazic,

Thank you for the update.

We can achieve your requirement by writing the behaviors for DockingManager in which we have canceled the Closing event of DocumentContainer based on the result of ModalDialog. We have prepared a sample based on your requirement. Please download the sample from the below link.

Sample: DockingManager_Sample

Regards,
Subashini M.


ZL Zeljko Lazic July 21, 2017 02:57 PM UTC

In my application it's the state of the view models (changed or unchanged) that determine whether a modal dialog should be shown (which is handled by the shell). Is it possible to define a new behaviour in the DockingAdapterView (or ViewModel), and not in the seperate DockingAdapterMVVM2015 assembly?



SM Subashini Mahendran Syncfusion Team July 24, 2017 12:00 PM UTC

Hi Zeljko Lazic,

It is not possible to define the new behavior in DockingAdapterView or ViewModel. Instead, we can achieve your requirement by CloseButtonClick event of DockingManager in ViewModel where we have Canceled the Closing of active document based on the result of ModalDialog. But it is not possible to achieve the requirement in XAML. We have prepared a sample based on your requirement. Please download the sample from the below link.

Sample: DockingManager_ModifiedSample 
  
Regards, 
Subashini M. 



ZL Zeljko Lazic July 24, 2017 05:24 PM UTC

This will work for me! Thanks for your help Subashini.



SM Subashini Mahendran Syncfusion Team July 25, 2017 08:41 AM UTC

Hi Zeljko Lazic,

We are glad to know that your issue has been solved. Please let us know if you need any other assistance.

Regards,
Subashini M.

Loader.
Live Chat Icon For mobile
Up arrow icon