Customizing menus in BrowseFeaturesControl

As shown previously, BrowseFeaturesControl exposes FeatureListBox and MapControl as properties, allowing the menu items of these controls to be customized.

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

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 why you would want to do this would be writing a Flash Feature command. Such a command would be added to the menu in a feature list and would make sense within the context of BrowseFeaturesControl, which contains a map control, but does not make sense within the context of a feature list box, however. These events would allow you to add a Flash Feature command only to those FeatureListBox controls within BrowseFeaturesControl.

public partial class  BrowseFeaturesControl : UserControl
{
  public static event EventHandler<CreatingBrowseFeaturesControlMenuItemsEventArgs> CreatingBrowseFeaturesControlMapMenuItems;
  public static event EventHandler<CreatingBrowseFeaturesControlMenuItemsEventArgs> CreatingBrowseFeaturesControlFeatureMenuItems;
}

 public class CreatingBrowseFeaturesControlMenuItemsEventArgs : EventArgs
{
  public BrowseFeaturesControl BrowseFeaturesControl { get; }
}

The pattern for globally customizing the menus within BrowseFeaturesControl is similar to globally customizing MapControl and FeatureListControl. Here 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 examples…
  }

  void RoutedGlobalBrowseFeatureCommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
  {
    // Similar to previous examples
  }
 
  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);
  }


9/20/2011