Nate Laff
05.06.2010
Hi Nate,
The SaveAndClose action is executed by sequentially committing the object space, and closing the view using the View.Close method. If you only cancel the commitment, the View.Close method displays the confirmation dialog. If you also want to cancel view closing programmatically, cancel the SaveAndClose action instead. For example:
[C#]public class MyController : ViewController { private void SaveAndCloseAction_Executing(Object sender, CancelEventArgs e) { e.Cancel = true; } protected override void OnActivated() { base.OnActivated(); DetailViewController controller = Frame.GetController<DetailViewController>(); if(controller != null) { controller.SaveAndCloseAction.Executing += new System.ComponentModel.CancelEventHandler(SaveAndCloseAction_Executing); } } protected override void OnDeactivating() { base.OnDeactivating(); DetailViewController controller = Frame.GetController<DetailViewController>(); if(controller != null) { controller.SaveAndCloseAction.Executing -= new System.ComponentModel.CancelEventHandler(SaveAndCloseAction_Executing); } } }
Thanks,
Michael.
Is this still an open suggestion? THe provided solution doesn't work since all my stuff happens in the Committing event handler. I don't want to handle it in the save and close since there is more than one way to commit the transaction, but I need to be able to supress the cancel dialog from the save and close.
Hi Nate,
I believe that a canceled commitment shouldn't automatically suppress the confirmation dialog, because these parts are generally unrelated. Besides, without the confirmation dialog, the user won't be informed that his changes were canceled.
So, we solve this specific scenario by creating a controller. Please try the following code, and let us know if this helps:
[C#]public class MyWinDetailViewController : WinDetailViewController { private bool wasObjectSpaceCommited; private void ObjectSpace_Committed(object sender, EventArgs e) { wasObjectSpaceCommited = true; } protected override void SaveAndClose(SimpleActionExecuteEventArgs args) { wasObjectSpaceCommited = false; ObjectSpace.Committed += new EventHandler(ObjectSpace_Committed); ObjectSpace.CommitChanges(); ObjectSpace.Committed -= new EventHandler(ObjectSpace_Committed); if(wasObjectSpaceCommited) { View.Close(); } } }
Thanks,
Michael.
Thanks Michael,
This almost works for me, but it activates on all on all ViewControllers (and actually caused me to lose save, save & close, save & new actions on some views) I need to be able to control this on a per viewcontroller basis. i think i can deal with this by id (not desireable) but not sure how to get the actions back on the views that lost them...?
Michael,
Perhaps it will help you to understand my task better with a more detailed description of what i'm doing.
In my software, users can process credit cards.
They type in the credit card number, expiration date, etc...
There is an unbound checkbox that says "Process credit card payment when saving"
If this is checked, the credit card is authorized, and returned as either Authorized or not.
I do all of the authorization in the "On Committing" event handler. If the authorization fails, I cancel the commit so the user can potentially correct any error in the credit card number, or expiration date. The problem is, the dialog that confirms canceling is confusing users. I need this to be supressed when this ViewController is active.
Is your intention to post an answer to your own question?
- If so, then proceed.
- If you simply wanted to post additional information, ask for further clarification, or to just say "Thanks!", please click Leave a Comment.
- If you wish to edit your original question, please use the Edit button in the Toolbox at the top right corner of that entry.
Facebook
Twitter
Google+