BrowseFeaturesControl menus

As shown in the customize feature list menu topic, BrowseFeaturesControl exposes FeatureListBox and MapControl as read-only properties, allowing the menu items of these controls to be customized together.

Extending the map and feature list menus in all browse features controls

BrowseFeaturesControl exposes two static events that are raised each time the menu items collection of FeatureListBox or MapControl within BrowseFeaturesControl is created. This allows a developer to globally customize the menus of all feature list and/or map control menus, but only those controls within BrowseFeaturesControl. An example of this is writing a Flash Feature command. Such a command is added to the menu in a feature list and makes sense within the context of BrowseFeaturesControl, which contains a map control. It does not make sense within the context of a feature list box, however. These events allow you to add a Flash Feature command only to those FeatureListBox controls within BrowseFeaturesControl.

public static event EventHandler<CreatingBrowseFeaturesControlMenuItemsEventArgs> CreatingBrowseFeaturesControlMapMenuItems;

public static event EventHandler<CreatingBrowseFeaturesControlMenuItemsEventArgs> CreatingBrowseFeaturesControlFeatureMenuItems;

The pattern for globally customizing the menus within BrowseFeaturesControl is similar to globally customizing MapControl and FeatureListControl individually. The following is an example:

class MyExtension :  ProjectExtension
{
  public static readonly RoutedUICommand RoutedGlobalBrowseMapCommand =
    new RoutedUICommand("Hello", "RoutedGlobalBrowseMapCommand", typeof(MyExtension));
 
  public static readonly RoutedUICommand RoutedGlobalBrowseFeatureCommand =
    new RoutedUICommand("Hello", "RoutedGlobalBrowseFeatureCommand", typeof(MyExtension));
 
  public MyExtension()
  {
    ESRI.ArcGIS.Mobile.Client.Controls.BrowseFeaturesControl.CreatingBrowseFeaturesControlMapMenuItems += new EventHandler<CreatingBrowseFeaturesControlMenuItemsEventArgs>(BrowseFeaturesControl_CreatingBrowseFeaturesControlMapMenuItems);
 
    ESRI.ArcGIS.Mobile.Client.Controls.BrowseFeaturesControl.CreatingBrowseFeaturesControlFeatureMenuItems += new EventHandler<CreatingBrowseFeaturesControlMenuItemsEventArgs>(BrowseFeaturesControl_CreatingBrowseFeaturesControlFeatureMenuItems);
  }                                                                  
 
  void BrowseFeaturesControl_CreatingBrowseFeaturesControlMapMenuItems(object sender, CreatingBrowseFeaturesControlMenuItemsEventArgs e)
  {
    MenuItem menuItem = new MenuItem();
    menuItem.Header = "Hello";
    menuItem.Command = RoutedGlobalBrowseMapCommand;
    menuItem.CommandTarget = e.BrowseFeaturesControl;
    e.BrowseFeaturesControl.MapControl.MenuItems.Add(menuItem);
 
    CommandBinding commandBinding = new CommandBinding(RoutedGlobalBrowseMapCommand);
    commandBinding.Executed += new ExecutedRoutedEventHandler(RoutedGlobalBrowseMapCommandBinding_Executed);
    e.BrowseFeaturesControl.CommandBindings.Add(commandBinding);
  }
 
  void BrowseFeaturesControl_CreatingBrowseFeaturesControlFeatureMenuItems(object sender, CreatingBrowseFeaturesControlMenuItemsEventArgs e)
  {
    MenuItem menuItem = new MenuItem();
    menuItem.Header = "Hello";
    menuItem.Command = RoutedGlobalBrowseFeatureCommand;
    menuItem.CommandTarget = e.BrowseFeaturesControl;
    e.BrowseFeaturesControl.FeatureList.MenuItems.Add(menuItem);
 
    CommandBinding commandBinding = new CommandBinding(RoutedGlobalBrowseFeatureCommand);
    commandBinding.Executed += new ExecutedRoutedEventHandler(RoutedGlobalBrowseFeatureCommandBinding_Executed);
    e.BrowseFeaturesControl.CommandBindings.Add(commandBinding);
  }
 
  void RoutedGlobalBrowseMapCommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
  {
    // Similar to previous example.
    // Perform some action when menuitem is clicked
  }

  void RoutedGlobalBrowseFeatureCommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
  {
    // Similar to previous examples
    // Perform some action when menuitem is clicked
  }
 
  protected override void Uninitialize()
  {
    // Stop listening to events
    ESRI.ArcGIS.Mobile.Client.Controls.BrowseFeaturesControl.CreatingBrowseFeaturesControlMapMenuItems -= new EventHandler<CreatingBrowseFeaturesControlMenuItemsEventArgs>(BrowseFeaturesControl_CreatingBrowseFeaturesControlMapMenuItems);
 
    ESRI.ArcGIS.Mobile.Client.Controls.BrowseFeaturesControl.CreatingBrowseFeaturesControlFeatureMenuItems -= new EventHandler<CreatingBrowseFeaturesControlMenuItemsEventArgs>(BrowseFeaturesControl_CreatingBrowseFeaturesControlFeatureMenuItems);
  }

1/7/2015