When feature collection begins/ends

The CollectFeaturesTask class contains events that are raised when collection of a new feature begins (CollectionStarted) and collection of a new feature is either finished or canceled (CollectionCompleted):

public event EventHandler CollectionStarted;
public event EventHandler<CanceledEventArgs> CollectionCompleted;

The CollectionStarted event is raised after you select the type of feature to create. At this point, the CollectFeaturesTask.Feature property contains a reference to the new feature being created. The CollectionCompleted event is raised after either the collection of the new feature has finished successfully or the feature collection is canceled. If the Canceled property of the CanceledEventArgs parameter passed to the CollectionCompleted event handler is true, feature collection was canceled; otherwise, feature collection finished successfully.

Following is an example of an extension that listens to these events:

public class  FeatureCollectionCustomizationExtension : ProjectExtension
{
  private CollectFeaturesTask _collectFeaturesTask;

  protected override void OnOwnerInitialized()
  {
    _collectFeaturesTask = MobileApplication.Current.FindTask(typeof(CollectFeaturesTask)) as CollectFeaturesTask;
    if (_collectFeaturesTask != null)
    {
      _collectFeaturesTask.CollectionStarted += new EventHandler(_collectFeaturesTask_CollectionStarted);
      _collectFeaturesTask.CollectionCompleted += new EventHandler<CanceledEventArgs>(_collectFeaturesTask_CollectionCompleted);
    }
  }

  protected override void Uninitialize()
  {
    if (_collectFeaturesTask != null)
    {
      _collectFeaturesTask.CollectionStarted -= new EventHandler(_collectFeaturesTask_CollectionStarted);
      _collectFeaturesTask.CollectionCompleted -= new EventHandler<CanceledEventArgs>(_collectFeaturesTask_CollectionCompleted);
      _collectFeaturesTask = null;
    }
  }

  void _collectFeaturesTask_CollectionStarted(object sender, EventArgs e)
  {
    CollectFeaturesTask collectFeaturesTask = sender as CollectFeaturesTask;
    ESRI.ArcGIS.Mobile.Client.Windows.MessageBox.ShowDialog(String.Format("Started collecting a new {0}", collectFeaturesTask.Feature.FeatureType.Name));
  }

  void _collectFeaturesTask_CollectionCompleted(object sender, CanceledEventArgs e)
  {
    CollectFeaturesTask collectFeaturesTask = sender as CollectFeaturesTask;
    StringBuilder builder = new StringBuilder();
    if (e.Canceled)
    {
      builder.AppendLine("Feature collection was canceled");
    }
    else
    {
      builder.AppendLine(String.Format("Successfully collected {0}!", collectFeaturesTask.Feature.DisplayName));
    }
    ESRI.ArcGIS.Mobile.Client.Windows.MessageBox.ShowDialog(builder.ToString());
  }
}


9/20/2011