I knew that - in fact I was spending several hours: I have a lot of issues with that!
- Simple code (copied directly from some samples:)
protected override async Task<bool> OnSketchCompleteAsync(Geometry geometry)
{
if (Module1.GfxViewModel == null) return false;
var popupContent = await QueuedTask.Run(() =>
{
var mapView = MapView.Active;
if (mapView == null) return null;
var popups = new List<PopupContent>();
var results = mapView.GetFeatures(geometry);
if (results != null && results.Any())
{
foreach (var kvp in results)
{
kvp.Value.ForEach(id => popups.Add(new GfxPopupContent(kvp.Key, id, kvp.Key == Module1.GfxViewModel.DeltaLayer)));
}
mpView.FlashFeature(results);
}
return popups;
})
ActiveMapView.ShowCustomPopup(popupContent, m_commands ?? (m_commands = CreateCommands()), true);
return true;
}
I can deactivate this Tool by going in the Ribbon and activate the Explore Map Tool. I can reactivate it again, but then I have to click twice (once to start the rectangle and second to end the rectangle. After reactivating the tool, even if I click and drag, I have to click again for the sketching to end!
This is (a simplified version of) the constructor:
public PickupTool()
{
IsSketchTool = true;
SketchType = SketchGeometryType.Rectangle;
Cursor = GetCursor("RectangleCursor.cur");
UseSnapping = true;
SketchOutputMode = SketchOutputMode.Screen;
}
As I have checked again and again, nothing executes twice (except OnSketchCompleteAsync) when activating the other tool and reactivating this one!
2. Before line 23, I'm adding this code:
try
{
//await SetCurrentToolAsync(DAML.Tool.esri_mapping_exploreTool);
var cmd = GetPlugInWrapper(DAML.Tool.esri_mapping_exploreTool) as ICommand;
if ((cmd != null) && cmd.CanExecute(null))
{
cmd.Execute(null);
}
}
catch (NullReferenceException)
{
}
I have a choice of (line 03) SetCurrentToolAsync or the code from line 04 to 08.
SetCurrentToolAsync is slow, but also executes only one. On second attempt it gives a NullRefferenceExemption. It also comes with the same behavior of clicking twice to select a rectangle on the second attempt, before crashing the application without catching the same exception in the catch block!
The un-commented code (04-08) works better (does not crashes,) but cmd.CanExecute alternates between false and true! So it selects the Explore Tool every second selection.
3. Anyway, selecting that tool makes the popup to disappear, so using this way, in this place would be useless if it would have worked correctly.
4. A better way would have been to be able to deactivate the Pick Tool after the popup closes(, as when the user clicks X or outside it...) However I cannot find any way to wait for ShowCustomPopup method to close the popup...
(Sorry for such long replay, but I've spent most of this day on it! I think it may be helpful...)