When feature collection begins and 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<CompletedEventArgs> 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 CompletedEventArgs.Status is equal to CompletedStatus.Canceled enum, the feature collection was canceled; otherwise, the feature collection finished successfully.
The 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<CompletedEventArgs>(_collectFeaturesTask_CollectionCompleted);
}
}
protected override void Uninitialize()
{
if (_collectFeaturesTask != null)
{
_collectFeaturesTask.CollectionStarted -= new EventHandler(_collectFeaturesTask_CollectionStarted);
_collectFeaturesTask.CollectionCompleted -= new EventHandler<CompletedEventArgs>(_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, CompletedEventArgs e)
{
CollectFeaturesTask collectFeaturesTask = sender as CollectFeaturesTask;
StringBuilder builder = new StringBuilder();
if (e.Status.Equals(CompletedStatus.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());
}
}