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 is a collection and can be extended and customized in the same manner as other menus in the application.
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 read-only properties.
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.
MenuItem menuItem = new MenuItem();
WorkListTask workListTask = (WorkListTask)MobileApplication.Current.Project.Tasks.GetFirstExtensionOfType(typeof(WorkListTask));
FeatureListBox featureListBox = workListTask.WorkListPage.BrowseFeaturesControl.FeatureList;
// Similar to previous examples
featureListBox.MenuItems.Add(menuItem);
Extending all feature list menus
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
The following code example 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.FeatureListBox.CommandBindings.Add(commandBinding);
}
void RoutedGlobalFeatureCommandBinding_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.FeatureListBox.CreatingFeatureListBoxMenuItems -= new EventHandler<CreatingFeatureListBoxMenuItemsEventArgs>(FeatureListBox_CreatingFeatureListBoxMenuItems);
}
}