I have a VM controlling a custom dock pane. The VM at some point starts vertex editing via esri_editing_EditVerticesModifyFeature plugin wrapper.
Just before that I set up an event handler for when the vertex editing bit is ended by the user - via SketchCompletedEvent or SketchCanceledEvent
SubscriptionToken canceledToken = null;
SubscriptionToken completedToken = null;
canceledToken = ArcGIS.Desktop.Mapping.Events.SketchCanceledEvent.Subscribe(async ags =>
{
await HandleCombinedSketchDone(canceledToken, completedToken);
});
completedToken = ArcGIS.Desktop.Mapping.Events.SketchCompletedEvent.Subscribe(async ags =>
{
await HandleCombinedSketchDone(canceledToken, completedToken);
});
await FrameworkApplication.SetCurrentToolAsync(null);
var editCommand = FrameworkApplication.GetPlugInWrapper("esri_editing_EditVerticesModifyFeature") as ICommand;
if (editCommand != null && editCommand.CanExecute(null))
{
editCommand.Execute(null);
}
These events appear to fire super rarely. I have not been able to find a pattern. Can anyone shed some light on this or am I doing something wrong?
In the event handler method HandleCombinedSketchDone I unsubsribe from the events and activate the current pane:
private async Task HandleCombinedSketchDone(SubscriptionToken canceledToken, SubscriptionToken completedToken)
{
ArcGIS.Desktop.Mapping.Events.SketchCanceledEvent.Unsubscribe(canceledToken);
ArcGIS.Desktop.Mapping.Events.SketchCompletedEvent.Unsubscribe(completedToken);
MapView.Active.Map.ClearSelection();
await Application.Current.Dispatcher.Invoke(() =>
{
this.Activate();
});
}
The buttons that should (and sometimes do) fire those events are the Finish/Cancel buttons on the Modify Features pane:
