I'm currently facing the problem that I need to add an exit condition for sketching geometries using the SketchEditor. The sketch editor should be finished/completed as soon as the sketched geometry fullfills the condition (e.g. has exactly 4 points).
To achieve this I registered to the GeometryChanged event, check for the exit condition and call the CompleteCommand if it mets the condition:
<SPAN class="keyword token">private</SPAN> <SPAN class="keyword token">void</SPAN> <SPAN class="token function">SketchEditorOnGeometryChanged</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">object</SPAN> sender<SPAN class="punctuation token">,</SPAN> GeometryChangedEventArgs e<SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">this</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">CheckValidity</SPAN><SPAN class="punctuation token">(</SPAN>e<SPAN class="punctuation token">.</SPAN>NewGeometry<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">&&</SPAN> <SPAN class="keyword token">this</SPAN><SPAN class="punctuation token">.</SPAN>sketchEditor<SPAN class="punctuation token">.</SPAN>CompleteCommand<SPAN class="punctuation token">.</SPAN><SPAN class="token function">CanExecute</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">this</SPAN><SPAN class="punctuation token">.</SPAN>sketchEditor<SPAN class="punctuation token">.</SPAN>CompleteCommand<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="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>However, the call to CompleteCommand will cause an NullReferenceException, because it will set the geometry of the SketchEditor to null, but the SketchEditor seems to use the value of geometry after the GeometryChanged event.
Am I missing something or is there no way to achieve such an exit condition?