Use the SetIsEditingEnabledAsync method to enable or disable editing within the application.
// if not editing if (!Project.Current.IsEditingEnabled) { var res = MessageBox.Show("You must enable editing to use editing tools. Would you like to enable editing?", "Enable Editing?", System.Windows.MessageBoxButton.YesNoCancel); if (res == System.Windows.MessageBoxResult.No || res == System.Windows.MessageBoxResult.Cancel) { return; } Project.Current.SetIsEditingEnabledAsync(true); }
// if editing if (Project.Current.IsEditingEnabled) { var res = MessageBox.Show("Do you want to disable editing? Editing tools will be disabled", "Disable Editing?", System.Windows.MessageBoxButton.YesNoCancel); if (res == System.Windows.MessageBoxResult.No || res == System.Windows.MessageBoxResult.Cancel) { return; } //we must check for edits if (Project.Current.HasEdits) { res = MessageBox.Show("Save edits?", "Save Edits?", System.Windows.MessageBoxButton.YesNoCancel); if (res == System.Windows.MessageBoxResult.Cancel) return; else if (res == System.Windows.MessageBoxResult.No) Project.Current.DiscardEditsAsync(); else { Project.Current.SaveEditsAsync(); } } Project.Current.SetIsEditingEnabledAsync(false); }
// ApplicationOptions.EditingOptions.EnableEditingFromEditTab is true // ApplicationOptions.EditingOptions.IsSingleWorkspaceEditSession is true var project = Project.Current; // check if already editing if (project.IsEditingEnabled) { // save or discard any edits if (project.HasEdits) { var res = MessageBox.Show("Save edits?", "Save Edits?", System.Windows.MessageBoxButton.YesNoCancel); if (res == System.Windows.MessageBoxResult.Cancel) return; else if (res == System.Windows.MessageBoxResult.No) await project.DiscardEditsAsync(); else await project.SaveEditsAsync(); } // close the edit session await project.SetIsEditingEnabledAsync(false); } // find a layer var mm = MapView.Active.Map.GetLayersAsFlattenedList().FirstOrDefault(l => l.Name == "Roads"); if (mm == null) return; // start the edit session on the workspace attached to the layer var success = await project.SetSingleEditWorkspaceAsync(mm); // if success = true then an edit session was started // and project.IsEditingEnabled will be true
Target Platforms: Windows 11, Windows 10