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.
Unfortunately, activation email could not send to your email. Please try again.

prevent viewmodel within document container from closing

Thread ID:

Created:

Updated:

Platform:

Replies:

131616 Jul 19,2017 02:59 PM Jul 25,2017 04:41 AM WPF 7
loading
Tags: DocumentContainer
Zeljko Lazic
Asked On July 19, 2017 02:59 PM

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.

Subashini Mahendran [Syncfusion]
Replied On July 20, 2017 09:02 AM

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.
 


Zeljko Lazic
Replied On July 20, 2017 09:25 AM

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

Subashini Mahendran [Syncfusion]
Replied On July 21, 2017 08:10 AM

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.

Zeljko Lazic
Replied On July 21, 2017 10:57 AM

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?


Subashini Mahendran [Syncfusion]
Replied On July 24, 2017 08:00 AM

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. 


Zeljko Lazic
Replied On July 24, 2017 01:24 PM

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


Subashini Mahendran [Syncfusion]
Replied On July 25, 2017 04:41 AM

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.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;