What if we wanted to create a custom activity like the PrePostSequence and have someone else who does not have Visual Studio use it? Many products allow end users to customize workflows. Windows Workflow Foundation 4 allows us to host the designer in an application quite easily. In this article, we will host the designer and use your custom activity.
- Start Microsoft Visual Studio 2010 from Start | All Programs | Microsoft Visual Studio 2010.
- To begin this project we can use the solution we finished from the previous article Activity Designers
- In the Solution Explorer, right click on the HelloWorkflow solution and select Add / New Project.
- From the Windows templates Add new WPF Application named HelloDesigner.
- Set the HelloDesigner project as the Startup project. To do this, in the Solution Explorer, right click on the HelloDesigner project and point to Set as Startup Project.
the Solution Explorer, right-click on the HelloDesigner
project and point to Add references.
Choose the following assemblies from the .Net tab
the Projects tab, add the following assemblies:
MainWindow.xaml and modify it as
- Open MainWindow.xaml.cs (C#) or MainWindow.xaml.vb, to do this, right-click the MainWindow.xaml file and choose View Code (F7).
the following namespace directives:
a field of type WorkflowDesigner:
a new function named RegisterMetadata
Note :This function enables the designer metadata store
When you host the designer you can control the toolbox. You choose what controls will appear, the categories that will appear in, and even the names of the controls.
a function named CreateToolboxControl,
which will create and populate the toolbox with four items:
a function named AddDesigner which
will add the designer to your window:
MainWindow’s constructor to call the functions you have just added:
- Ensure that HelloDesigner is set as the startup project.
- Press F5 to launch the application in debug mode.
- When the design window appears drop a PrePostSequence on the designer surface.
should see the following:The HelloDesigner application hosting the WorkflowDesigner