Customizing finish collection options
The CollectFeaturesTask class contains an event, CreatingFinishCollectionCommands, that is raised after a feature has been successfully collected and before the user is prompted to choose a finish action. Listening to this event allows you to customize the finish actions available by either removing an existing action or adding a custom action.
public event EventHandler<CreatingFinishCollectionCommandsEventArgs> CreatingFinishCollectionCommands;
The CreatingFinishCollectionCommandsEventArgs class contains a list of IUICommand objects available after you've finished collecting a feature.
public class CreatingFinishCollectionCommandsEventArgs : EventArgs { public IList<IUICommand> FinishCollectionCommands { get; protected set; } }
The following is an example of an extension that listens to the CreatingFinishCollectionCommands event and modifies the finish collection commands:
public class FinishCollectionCustomizationExtension : ProjectExtension
{
private CollectFeaturesTask _collectFeaturesTask;
protected override void Initialize() {}
protected override void OnOwnerInitialized()
{
_collectFeaturesTask = MobileApplication.Current.FindTask(typeof(CollectFeaturesTask)) as CollectFeaturesTask;
if (_collectFeaturesTask != null)
{
_collectFeaturesTask.CreatingFinishCollectionCommands += new EventHandler<CreatingFinishCollectionCommandsEventArgs>(_collectFeaturesTask_CreatingFinishCollectionCommands);
}
}
protected override void Uninitialize()
{
if (_collectFeaturesTask != null)
{
_collectFeaturesTask.CreatingFinishCollectionCommands -= new EventHandler<CreatingFinishCollectionCommandsEventArgs>(_collectFeaturesTask_CreatingFinishCollectionCommands);
_collectFeaturesTask = null;
}
}
void _collectFeaturesTask_CreatingFinishCollectionCommands(object sender, CreatingFinishCollectionCommandsEventArgs e)
{
UICommand command = new UICommand("Custom Action", param => this.CustomFinishCommandExecute());
Uri uri = new Uri("pack://application:,,,/CollectFeaturesCustomization;Component/smiley.png");
command.Image = new System.Windows.Media.Imaging.BitmapImage(uri);
e.FinishCollectionCommands.Add(command);
}
private void CustomFinishCommandExecute()
{
ESRI.ArcGIS.Mobile.Client.Windows.MessageBox.ShowDialog("Perform some custom action...");
}
}