In this blog, I will talk about the dependency property used in Windows Workflow Foundation (WWF) for a meta data property. You can read more what dependency property are used for in the Essential Windows Workflow Foundation book (Chapter 7) which can be found in Safari Book Online or Google Book Preview. The Tomblog and Developer.com give a very good explanation of the dependency property as well. The Stuart Cox’s Tech Punch Blog gives a very concise summary of how to create and when to use the dependency property.
First of all, a meta data property is a property which can be changed during the design time, but it can not be changed during the runtime.
In this blog, I will create a meta data property on a custom activity. Then, I would use the custom activity in a workflow. When editing a workflow in the workflow designer, you would be able to edit the meta data property of a custom activity.
1. A workflow sequential project is created. There would be a default one workflow called “Workflow1″ available.
2. Add a new custom activity as shown below. Accept the default file name which is “Activity1.”
3. Open the code part of the Activity1.cs. Add a dependency property as shown below.
This dependency property is declared as meta data according to the last parameter of the register function which is “new PropertyMetadata( DependencyPropertyOptions.Metadata.”
public partial class Activity1: SequenceActivity
{
public static DependencyProperty TaskTemplate_idProperty = System.Workflow.ComponentModel.DependencyProperty.Register(“TaskTemplate_id“, typeof(int),typeof(Activity1) , new PropertyMetadata( DependencyPropertyOptions.Metadata));
[Description("Task template id")]
[Category("Metadata Properties")]
[Browsable(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public int TaskTemplate_id
{
get
{
return ((int)(base.GetValue(TaskTemplate_idProperty)));
}
set
{
base.SetValue(TaskTemplate_idProperty, value);
}
}
….
}
4. Just put one code activity into your custom project as shown below.
In the Properties window of this custom activity, add a code function for the code activity 1 by writing a name of the function in the “ExecuteCode” text field and press enter. In this case, I entered “ca1a” for the function name.
5. A function called “ca1a” of the custom activity is created.
Add the WriteLine statement to print the value of TaskTemplate_id property found in the custom activity “Activity1″ out on the screen. Following is the complete function.
private void ca1a(object sender, EventArgs e)
{
Console.WriteLine(“Activity TaskTemplate_id : “ + TaskTemplate_id);
}
Build the project to see if there is any error.
6. Open the workflow designer of the Workflow1. If build is successful, a icon of new custom activity would appear on the toolbox. Drag the custom activity into the workflow.

Adding a custom activity into a workflow and you can edit the value of the meta data called TaskTemplate_id
7. There is a default function for running a workflow come with the project template located in the “Program.cs” file. Add the Readline statement at the last line of the main function, so the program does not terminate immediately. It will wait for the readLine function.
Console.ReadLine();
8. Run the workflow. You would see the following output.
Find the project file here.




[...] to define two dependency properties as metadata for this composite activity. Please refer to my previous blog for creating a [...]
Pingback by Communication between inside and outside of a workfow in windows workflow « Sukasom — October 20, 2008 @ 9:14 am
Nice post, and thanks for the plug! I’ll add a link back at you.
Comment by Stuart — November 8, 2008 @ 6:07 pm