Events that are triggered before an action has taken place (i.e. DocumentSaving) are often cancellable. (Use the Cancellable property to determine if the event can be cancelled.) For example, you may want to check some criteria are met in a model before it is saved. By registering for the DocumentSaving or DocumentSavingAs event, for example, you can check for certain criteria in the document and cancel the Save or Save As action. Once cancelled, an event cannot be un-cancelled.
Code Region 24-2: Canceling an Event |
private void CheckProjectStatusInitial(Object sender, DocumentSavingAsEventArgs args) { Document doc = args.Document; ProjectInfo proInfo = doc.ProjectInformation; // Project information is only available for project document. if (null != proInfo) { if (string.IsNullOrEmpty(proInfo.Status)) { // cancel the save as process. args.Cancel = true; MessageBox.Show("Status project parameter is not set. Save is aborted."); } } } |