In workflow foundation 4.0, we can pass data from a Host application to workflow using arguments. We can add the InArguments to the workflow in two ways. Either the user needs to Manually create the required InArguments or we need a mechanism to add the same dynamically.
For adding the InArguments dynamically, handle the Load event of the Designer and Process the Properties collection associates with the Root ModelItem. This Collection consist of all the InArguments, OutArguments and Variables associated with the Main Workflow.
void MyActivityDesigner_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
ModelItemCollection argumentsCollection = this.ModelItem.Root.Properties[“Properties”].Collection;
if (!argumentsCollection.ToList().Any(p => (p.GetCurrentValue() as DynamicActivityProperty).Name == “HostData”))
{
argumentsCollection.Add(new DynamicActivityProperty
{
Name = “HostData”,
Type = typeof(InArgument<WorkUnitSchema>)
});
}
}