views:

37

answers:

2

This article shows how to create a custom activity in a rehosted Workflow designer (with Workflow Foundation 4). In that example, a MyDelayActivity is created by implementing the IActivityTemplateFactory interface, and specifying the default value to the Delay inputs.

However, is it possible to modify the inputs of the activity as well? For example, let's say I want to add a new StartProcess activity which takes a string and run the process specified by the string. I can implement this with the native activities by adding a InvokeMethod activity, specifying Process.Start as the method and a Collection containing the string as the parameter.

Can I simplify all these by just having a StartProcess box with only a string input?

+1  A: 

Sure, just create the activity to do the work and add InArgument properties to provide the data you need. When you drop the activity on the design surface you can use the property sheet to set the arguments. Alternatively you can create an activity designer to do the same on the design surface like for example the WriteLine activity.

Example:

public sealed class MyWriteLine : CodeActivity
{
    public InArgument<string> Text { get; set; }

    protected override void Execute(CodeActivityContext context)
    {
        string text = context.GetValue(this.Text);
        Console.WriteLine(text);
    }
}
Maurice
hmmm.. would you please give more hints as to where I should add the InArgument?
Louis Rhys
@Maurice Thanks! one more question, though. Now `MyWriteLine` appears in the GUI designer as an activity without no input. TO modify Text the user must use the Property sheet. Is it possible to make the GUI representation have a "Text" input, like the normal VS WriteLine?
Louis Rhys
Yes. Add an ActivityDesigner. This is a workflow aware WPF control that the WorkflowDesigner uses to render your activity. You can include controls like TextBox and databind them to your activity InArguments.
Maurice
thanks! apparently it's a bit complicated, lol
Louis Rhys
A: 

Additional information, there are two very helpful video tutorials in the MSDN website: Developing custom activities and Activity designers, and I assume the speaker is the same Maurice as the accepted answerer :)

Louis Rhys