This documentation is archived and is not being maintained.

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)

'Declaration
Public NotInheritable Class WorkflowMenuCommands _
	Inherits StandardCommands
'Usage
Dim instance As WorkflowMenuCommands

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.

Friend NotInheritable Class WorkflowMenuCommandService
    Inherits MenuCommandService
    Public Sub New(ByVal serviceProvider As IServiceProvider)
        MyBase.new(serviceProvider)
    End Sub 
    Public Overrides Sub ShowContextMenu(ByVal menuID As CommandID, ByVal x As Integer, ByVal y As Integer)

        If menuID.ID = WorkflowMenuCommands.SelectionMenu.ID Then 
            Dim contextMenu As New ContextMenu()

            For Each verb As DesignerVerb In Verbs
                Dim MenuItem As New MenuItem(verb.Text, AddressOf OnMenuClicked)
                MenuItem.Tag = verb
                contextMenu.MenuItems.Add(MenuItem)
            Next 

            Dim items As MenuItem() = GetSelectionMenuItems()
            If (items.Length > 0) Then

                contextMenu.MenuItems.Add(New MenuItem("-"))
                For Each item As MenuItem In items
                    contextMenu.MenuItems.Add(item)
                Next 

                Dim workflowView As WorkflowView = CType(GetService(GetType(WorkflowView)), WorkflowView)
                If workflowView Is Nothing Then
                    contextMenu.Show(workflowView, workflowView.PointToClient(New Point(x, y)))
                End If 
            End If 
        End If 
    End Sub 

    Private Function GetSelectionMenuItems() As MenuItem()

        Dim menuItems As New List(Of MenuItem)()

        Dim addMenuItems As Boolean = True 
        Dim selectionService As ISelectionService = CType(GetService(GetType(ISelectionService)), ISelectionService)
        If selectionService IsNot Nothing Then 

            For Each obj As Object In selectionService.GetSelectedComponents()
                If Not TypeOf obj Is Activity Then
                    addMenuItems = False 
                    Exit For 
                End If 
            Next 
        End If 


        If (addMenuItems) Then 

            Dim selectionCommands As New Dictionary(Of 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")

            For Each id As CommandID In selectionCommands.Keys

                Dim command As MenuCommand = FindCommand(id)
                If command IsNot Nothing Then 
                    Dim menuItem As New MenuItem(selectionCommands(id), AddressOf OnMenuClicked)
                    menuItem.Tag = command
                    menuItems.Add(menuItem)
                End If 
            Next 
        End If 

        Return menuItems.ToArray()
    End Function 

    Private Sub OnMenuClicked(ByVal sender As Object, ByVal e As EventArgs)

        Dim menuItem As MenuItem = CType(sender, MenuItem)
        If menuItem IsNot Nothing And TypeOf menuItem.Tag Is MenuCommand Then 
            Dim command As MenuCommand = CType(menuItem.Tag, MenuCommand)
            command.Invoke()
        End If 
    End Sub 
End Class

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

Protected Overrides Sub Initialize()
    MyBase.Initialize()

    Dim host As IDesignerLoaderHost = Me.LoaderHost
    If host IsNot Nothing Then
        host.RemoveService(GetType(IIdentifierCreationService))
        host.AddService(GetType(IIdentifierCreationService), New IdentifierCreationService(host))
        host.AddService(GetType(IMenuCommandService), New WorkflowMenuCommandService(host))
        host.AddService(GetType(IToolboxService), New Toolbox(host))
        Dim typeProvider As New TypeProvider(host)
        typeProvider.AddAssemblyReference(GetType(String).Assembly.Location)
        host.AddService(GetType(ITypeProvider), typeProvider, True)
        host.AddService(GetType(IEventBindingService), New EventBindingService())
    End If 
End Sub

System.Object
  System.ComponentModel.Design.StandardCommands
    System.Workflow.ComponentModel.Design.WorkflowMenuCommands

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
Show: