Export (0) Print
Expand All

WorkflowMenuCommands Class

Defines a set of CommandID fields that each corresponds to a command function provided by the workflow designers. This class cannot be inherited.

Namespace:  System.Workflow.ComponentModel.Design
Assembly:  System.Workflow.ComponentModel (in System.Workflow.ComponentModel.dll)

public sealed class WorkflowMenuCommands : StandardCommands

WorkflowMenuCommands contains a set of CommandID fields that can be used to specify a command to link when adding a command using the AddCommand method of the IMenuCommandService.

The following example demonstrates how to create a custom MenuCommandService. In this example, a context menu is created when the ShowContextMenu is called. In the GetSelectionMenuItems method, the WorkflowMenuCommands class is utilized to associate the proper menu commands provided by the workflow designer with their corresponding text. When this is finished, an event handler is associated with each command so that when the command is selected, the appropriate MenuCommand is invoked.

internal sealed class WorkflowMenuCommandService : MenuCommandService
    public WorkflowMenuCommandService(IServiceProvider serviceProvider)
        : base(serviceProvider)

    public override void ShowContextMenu(CommandID menuID, int x, int y)
        if (menuID == WorkflowMenuCommands.SelectionMenu)
            ContextMenu contextMenu = new ContextMenu();

            foreach (DesignerVerb verb in Verbs)
                MenuItem menuItem = new MenuItem(verb.Text, new EventHandler(OnMenuClicked));
                menuItem.Tag = verb;

            MenuItem[] items = GetSelectionMenuItems();
            if (items.Length > 0)
                contextMenu.MenuItems.Add(new MenuItem("-"));
                foreach (MenuItem item in items)

            WorkflowView workflowView = GetService(typeof(WorkflowView)) as WorkflowView;
            if (workflowView != null)
                contextMenu.Show(workflowView, workflowView.PointToClient(new Point(x, y)));

    private MenuItem[] GetSelectionMenuItems()
        List<MenuItem> menuItems = new List<MenuItem>();

        bool addMenuItems = true;
        ISelectionService selectionService = GetService(typeof(ISelectionService)) as ISelectionService;
        if (selectionService != null)
            foreach (object obj in selectionService.GetSelectedComponents())
                if (!(obj is Activity))
                    addMenuItems = false;

        if (addMenuItems)
            Dictionary<CommandID, string> selectionCommands = new Dictionary<CommandID, string>();
            selectionCommands.Add(WorkflowMenuCommands.Cut, "Cut");
            selectionCommands.Add(WorkflowMenuCommands.Copy, "Copy");
            selectionCommands.Add(WorkflowMenuCommands.Paste, "Paste");
            selectionCommands.Add(WorkflowMenuCommands.Delete, "Delete");
            selectionCommands.Add(WorkflowMenuCommands.Collapse, "Collapse");
            selectionCommands.Add(WorkflowMenuCommands.Expand, "Expand");
            selectionCommands.Add(WorkflowMenuCommands.Disable, "Disable");
            selectionCommands.Add(WorkflowMenuCommands.Enable, "Enable");

            foreach (CommandID id in selectionCommands.Keys)
                MenuCommand command = FindCommand(id);
                if (command != null)
                    MenuItem menuItem = new MenuItem(selectionCommands[id], new EventHandler(OnMenuClicked));
                    menuItem.Tag = command;

        return menuItems.ToArray();

    private void OnMenuClicked(object sender, EventArgs e)
        MenuItem menuItem = sender as MenuItem;
        if (menuItem != null && menuItem.Tag is MenuCommand)
            MenuCommand command = menuItem.Tag as MenuCommand;

To enable this service, call the AddService method of the LoaderHost property in a WorkflowDesignerLoader class as shown in the following example.

protected override void Initialize()

    IDesignerLoaderHost host = this.LoaderHost;
    if (host != null)
        host.AddService(typeof(IIdentifierCreationService), new IdentifierCreationService(host));
        host.AddService(typeof(IMenuCommandService), new WorkflowMenuCommandService(host));
        host.AddService(typeof(IToolboxService), new Toolbox(host));
        TypeProvider typeProvider = new TypeProvider(host);
        host.AddService(typeof(ITypeProvider), typeProvider, true);
        host.AddService(typeof(IEventBindingService), new EventBindingService());


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0

Community Additions

© 2015 Microsoft