Customizing the feature list menu

Several pages in the application contain a feature list control (FeatureListBox) that contains a context menu for each feature in the list. This menu may be extended/customized in the same manner as the map control.

public partial class  FeatureListBox
{
  public ObservableCollection<object> MenuItems { get; }
}

Most pages in the application host the FeatureListBox control within another control, BrowseFeaturesControl. BrowseFeaturesControl is composed of a feature list box and two tabs, which contain a map control and an attributes control. The feature list and map control are both exposed as properties:

public partial class  BrowseFeaturesControl : UserControl
{
  public FeatureListBox FeatureList { get; }
  public MapControl MapControl { get; }
}

Extending the feature list menu on the View Work List page

To customize the menu of a feature list box, you must first obtain a reference to it. Similar to customizing the menu for a map control, this is commonly done by first getting the desired task, then the appropriate page, then BrowseFeaturesControl, and finally the FeatureListBox control.

WorkListTask workListTask = (WorkListTask)MobileApplication.Current.Project.Tasks.GetFirstExtensionOfType(typeof(WorkListTask));
FeatureListBox featureListBox = workListTask.WorkListPage.BrowseFeaturesControl.FeatureList;
// Similar to previous examples
featureListBox.MenuItems.Add(...);

Extending all feature list menus

Similar to MapControl, the application framework provides the ability to customize the menu of all FeatureListBox instances. Like MapControl, the FeatureListBox class exposes a static event (CreatingFeatureListBoxMenuItems) that is raised each time an instance of FeatureListBox creates its collection of menu items, allowing it to be customized.

public static event  EventHandler<CreatingFeatureListBoxMenuItemsEventArgs>  CreatingFeatureListBoxMenuItems;
public class CreatingFeatureListBoxMenuItemsEventArgs : EventArgs
{
  public FeatureListBox FeatureListBox { get; }
}

Here is an example that adds a menu item to every FeatureListBox menu:

class MyExtension :  ProjectExtension
{
  public static readonly RoutedUICommand RoutedGlobalFeatureCommand =
    new RoutedUICommand("Hello", "RoutedGlobalFeatureCommand", typeof(MyExtension));
 
  public MyExtension()
  {
    ESRI.ArcGIS.Mobile.Client.Controls.FeatureListBox.CreatingFeatureListBoxMenuItems += new EventHandler<CreatingFeatureListBoxMenuItemsEventArgs>(FeatureListBox_CreatingFeatureListBoxMenuItems);
  }                                                                  
 
  void FeatureListBox_CreatingFeatureListBoxMenuItems(object sender, CreatingFeatureListBoxMenuItemsEventArgs e)
  {
    MenuItem menuItem = new MenuItem();
    menuItem.Header = "Hello";
    menuItem.Command = RoutedGlobalFeatureCommand;
    menuItem.CommandTarget = e.FeatureListBox;
    e.FeatureListBox.MenuItems.Add(menuItem);
 
    CommandBinding commandBinding = new CommandBinding(RoutedGlobalFeatureCommand);
    commandBinding.Executed +=new ExecutedRoutedEventHandler(RoutedGlobalFeatureCommandBinding_Executed);
    e.MapControl.CommandBindings.Add(commandBinding);
  }

  void RoutedGlobalFeatureCommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
  {
    // Similar to previous examples
  }
 
  protected override void Uninitialize()
  {
    // Stop listening to events
    ESRI.ArcGIS.Mobile.Client.Controls.FeatureListBox.CreatingFeatureListBoxMenuItems -= new EventHandler<CreatingFeatureListBoxMenuItemsEventArgs>(FeatureListBox_CreatingFeatureListBoxMenuItems);
  }
}


9/20/2011