I have a MapTool that will only be activated (OnToolActivateAsync) when one, and only one feature is selected. Then when the user finishes their sketch, the one and only selected item will have some work done to it (OnSketchCompleteAsync).
The problem that I find, is that after you activate the tool, if you click on the Clear Selection button, my map tool doesn't deactivate, so the validation of a selected item is no longer valid. i would either like my tool to deactivate when the Clear button is pressed, or have a way to catch the button being clicked from my maptool, and have the validation rerun. I have tried OnSelectionChangedAsync but that doesn't seem to catch the clear selection, as my tool is a sketch tool.
Here is my Activate Function that has the line to CheckForValidSelection. But after the tool is activated, I have no way of catching the selection clear button.
<SPAN class="keyword token">protected</SPAN> <SPAN class="keyword token">async</SPAN> <SPAN class="keyword token">override</SPAN> Task <SPAN class="token function">OnToolActivateAsync</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">bool</SPAN> hasMapViewChanged<SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">try</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="comment token">//this checks the map for only one feature selected and warns user if failed</SPAN>
<SPAN class="keyword token">bool</SPAN> validCheck <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">await</SPAN> <SPAN class="token function">CheckForValidSelection</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">//Exist if one thing and one thing only is not selected</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="operator token">!</SPAN>validCheck<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">return</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">//Setup the line symbol/snapping/tracing</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>_lineSymbol <SPAN class="operator token">==</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
_lineSymbol <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">await</SPAN> <SPAN class="token function">CreateLineSymbolAsync</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
SketchSymbol <SPAN class="operator token">=</SPAN> _lineSymbol<SPAN class="punctuation token">.</SPAN><SPAN class="token function">MakeSymbolReference</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">//General Snapping</SPAN>
Snapping<SPAN class="punctuation token">.</SPAN>IsEnabled <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">true</SPAN><SPAN class="punctuation token">;</SPAN>
Snapping<SPAN class="punctuation token">.</SPAN><SPAN class="token function">SetSnapMode</SPAN><SPAN class="punctuation token">(</SPAN>SnapMode<SPAN class="punctuation token">.</SPAN>Edge<SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">true</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
Snapping<SPAN class="punctuation token">.</SPAN><SPAN class="token function">SetSnapMode</SPAN><SPAN class="punctuation token">(</SPAN>SnapMode<SPAN class="punctuation token">.</SPAN>End<SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">true</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
Snapping<SPAN class="punctuation token">.</SPAN><SPAN class="token function">SetSnapMode</SPAN><SPAN class="punctuation token">(</SPAN>SnapMode<SPAN class="punctuation token">.</SPAN>Intersection<SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">true</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">//Set the command to Trace, possible bug as we have to set it then set it again</SPAN>
ICommand _trace <SPAN class="operator token">=</SPAN> FrameworkApplication<SPAN class="punctuation token">.</SPAN><SPAN class="token function">GetPlugInWrapper</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"esri_editing_TraceConstructor"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> ICommand<SPAN class="punctuation token">;</SPAN>
_trace<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Execute</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
_trace <SPAN class="operator token">=</SPAN> FrameworkApplication<SPAN class="punctuation token">.</SPAN><SPAN class="token function">GetPlugInWrapper</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"esri_editing_LineConstructor"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> ICommand<SPAN class="punctuation token">;</SPAN>
_trace<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Execute</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
_trace <SPAN class="operator token">=</SPAN> FrameworkApplication<SPAN class="punctuation token">.</SPAN><SPAN class="token function">GetPlugInWrapper</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"esri_editing_TraceConstructor"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> ICommand<SPAN class="punctuation token">;</SPAN>
_trace<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Execute</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">catch</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="token class-name">Exception</SPAN> e<SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="token function">LogError</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"OnToolActivateAsync"</SPAN><SPAN class="punctuation token">,</SPAN> e<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>