I am trying to explore the SketchEditor feature. I am trying to use the sketch editor in my application using MVVM pattern. The code of DRAW and EDIT , is written in ViewModel Class, whereas the COMPLETE button is binded to the CompleteCommand of SketchEditor. DRAW operation works absolutely fine on MouseDownEvent, but when I go for Edit , I get TaskCancelled Exception on line
var mapPoint = (MapPoint)await MyMapView.SketchEditor.StartAsync(SketchCreationMode.Point, false);
I am unable to understand why such problem is coming ??
The code runs absoultely fine , If I write everything in the code behind file ..
Can anyone help me with this issue ?
TaskCanceledException is expected when SketchEditor.StartAsync is called while it has not yet completed. Perhaps your edit cancels draw that is also triggered by MouseDown? Where you call SketchEditor.StartAsync, you can surround this with try-catch TaskCanceledException, you can check here SketchEditor properties and possibly determine if you were in the middle of draw or edit? Or perhaps add a check in your MouseDown event handler if SketchEditor is active `if(SketchEditor.Geometry != null) return`. There can only be one active sketch in your MapView, so you can either cancel or suspend one before starting the other; otherwise, the active sketch will be canceled.