/// <summary> /// Clear the graph if not empty /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MenuReset_Click(object sender, RoutedEventArgs e) { if (!MainCanvas.IsEmpty()) { MessageBoxResult result = MessageBox.Show("Would you like to save the current graph before openning a new one?", "Current graph is not saved!", MessageBoxButton.YesNoCancel, MessageBoxImage.Warning); if (result == MessageBoxResult.Yes) { SaveToFile(); } else if (result == MessageBoxResult.No) { MainCanvas.Children.Clear(); graph = new CanvasGraph(); } else if (result == MessageBoxResult.Cancel) { // do nothing } } else { MainCanvas.Children.Clear(); graph = new CanvasGraph(); } }
/// <summary> /// Terminate the application when main window is closed /// </summary> /// <param name="e"></param> protected override void OnClosing(System.ComponentModel.CancelEventArgs e) { if (!MainCanvas.IsEmpty()) { MessageBoxResult result = MessageBox.Show("Are you sure you want to exit?", "Current graph will be lost if you haven't saved it yet.", MessageBoxButton.YesNoCancel, MessageBoxImage.Warning); if (result == MessageBoxResult.Yes) { base.OnClosing(e); Application.Current.Shutdown(); } else { e.Cancel = true; }// end else/if } }