WPF/WF4 APPLICATION : VBWF4CustomeSequenceActivity


Generally, we use the built in Sequence activity to build a sequence workflow.
Sequence activity is a composite activity. in this sample I demonstrated
creating an customized composite activity: MySequenceActivity. and also
its activity designer so that you can use it in a workflow designer. If you
are going to create your own WF4 activity, you can use this sample as a


1. Open VBWF4CustomSequenceActivity.sln with Visual Studio 2010
2. Press Ctrl+F5.


1. Visual Studio 2010
2. .NET Framework 4.0


1. Create a Workflow Console Application base on .NET Framework 4.0.

2. Add a new Activity Designer to the project by following actions:
  a. Right click the project name and select Add|New Item...
  b. Click Workflow|Activity Designer. then name the file MySequenceDesigner.xaml

3. Open file MySequenceDesigner.xaml.cs and alter its code to:
<sap:ActivityDesigner x:Class="MySequenceDesigner"
           <sap:WorkflowItemsPresenter HintText="Drop Activities Here"
                                       Items="{Binding Path=ModelItem.Branches,Mode=TwoWay}">
                       <Path Margin="0,15,0,0"                                            
                                   Stroke="#FFA8B3C2" Fill="#FFFFFFFF"
                                   Data="F1 M 675.738,744.979L 665.7,758.492L 655.66,744.979L 675.738,744.979 Z "
                                   Width="16" Height="10" />
                       <StackPanel Orientation="Vertical"/>
Then, save and build the project.

4. Add a new code file named MySequenceActivity.vb, fill the file with the
  following code:
Imports System.ComponentModel
Imports System.Activities
Imports System.Collections.ObjectModel

Public Class MySequenceActivity
   Inherits NativeActivity

   Public Property Branches() As Collection(Of Activity)
           Return _Branches
       End Get
       Set(ByVal value As Collection(Of Activity))
           _Branches = value
       End Set
   End Property
   Private _Branches As Collection(Of Activity)

   Public Property Variables() As Collection(Of Variable)
           Return _Variables
       End Get
       Set(ByVal value As Collection(Of Variable))
           _Variables = value
       End Set
   End Property
   Private _Variables As Collection(Of Variable)

   Public Sub New()
       Branches = New Collection(Of Activity)()
       Variables = New Collection(Of Variable)()
   End Sub

   Dim activityCounter As Integer

   Protected Overrides Sub CacheMetadata(ByVal metadata As System.Activities.NativeActivityMetadata)


   End Sub

   Protected Overrides Sub Execute(ByVal context As System.Activities.NativeActivityContext)


   End Sub

   Protected Sub ScheduleActivities(ByVal context As NativeActivityContext)

       If activityCounter < Branches.Count Then

           context.ScheduleActivity(Me.Branches(activityCounter), AddressOf OnActivityCompleted)
           activityCounter = activityCounter + 1

       End If

   End Sub

   Protected Sub OnActivityCompleted(ByVal context As NativeActivityContext, ByVal completedInstance As ActivityInstance)


   End Sub

End Class
Then, save and build the project.

5. Open the default created Workflow1.xaml and drag the MySequenceActivity
  from the toolbox panel to the workflow designer. and create a simple
  workflow to test it.


A Developer's Introduction to Windows Workflow Foundation (WF) in .NET 4