One of the things I found really useful in Windows Workflow Foundation was the use of the Dependency Property. A dependency property is used to pass the information from the Workflow to the child activities. Let's say that your workflow takes "Amount", "UserName" and "Password" as input parameters and you need to pass those parameters to custom activities then you can make use the dependency property
One of the things I found really useful in Windows Workflow Foundation was the use of the Dependency Property. A dependency property is used to pass the information from the Workflow to the child activities. Let's say that your workflow takes "Amount", "UserName" and "Password" as input parameters and you need to pass those parameters to custom activities then you can make use the dependency property.
The first step is to declare the dependency property inside the activity.
public static DependencyProperty AmountProperty =
System.Workflow.ComponentModel.DependencyProperty.Register(
"Amount", typeof(double), typeof(DepositAmountActivity));
[Description("The new username for this user")]
[Category("User")]
[Browsable(true)]
[DesignerSerializationVisibility(
DesignerSerializationVisibility.Visible)]
public double Amount
{
get
{
return (double)base.GetValue(
DepositAmountActivity.AmountProperty);
}
set { base.SetValue(DepositAmountActivity.AmountProperty, value); }
}
The dependency property is marked as static but it is exposed as a public double Amount property. Now, you have to declare the same property for the workflow. Take a look at the code below:
public static DependencyProperty AmountProperty =
System.Workflow.ComponentModel.DependencyProperty.Register(
"Amount", typeof(double), typeof(PaymentProcessingWorkflow));
[Description("The new amount for this user")]
[Category("User")]
[Browsable(true)]
[DesignerSerializationVisibility(
DesignerSerializationVisibility.Visible)]
public double Amount
{
get
{
return (double)base.GetValue(
PaymentProcessingWorkflow.AmountProperty);
}
set { base.SetValue(PaymentProcessingWorkflow.AmountProperty, value); }
}
Thats it! Now, you can bind the activity property to the workflow property. By doing so the workflow will send the parameters automatically to the activity property. Take a look at the image below: