Windows Workflow Designer Glitch

I’ve had the opportunity to teach a course called What’s New in .Net 3.0, which includes a day spent on Windows Workflow Foundation. Overall, I think the tool story for WF is one of the best among all the “pillars” of .Net 3.0 (WPF, WCF, WF, CS). However, I have noticed a glitch in the designer support for WF: the VS 2008 workflow designer does not support activity binding for bool and enum dependency properties. Normally, when binding the property of one workflow activity to another, or to the workflow itself, you see a little ellipses button when you select the property in the Properties window.

 

Clicking that button brings up a dialog that lets you specify a binding for the activity. The great thing about data binding in general is that it takes care of the plumbing of keeping two data points in synch. What makes activity binding so great is that it allows you to have a purely declarative workflow without any code activities. That means you can represent it in XAML if you want, which allows you to change and use it, all without having to re-compile.

The glitch I’ve found is that the ellipses button does not appear when the property data type if either bool or an enum (it appears for strings, numbers, and for custom types). In the case of bools, the property window displays a drop down with values for true and false. For enum property types, it displays a drop down with the enum values.

This may be a limitation of the Visual Studio designer, but it’s unfortunate because it means you’re stuck having to write the binding code yourself if you wish to pass these property types between activities (alternatively you could write a hander for a code activity that explicitly sets the workflow property to that of the activity). The problem with having to write the code yourself is that it is complex, error prone and difficult to debug. So I really hope the WF designer team gets wind of this and fixes the problem. In the meantime, I wrote a code snippet that performs the activity binding. It generates a method that you can call from the workflow constructor.

Here is a VS 2008 project that demonstrates both the glitch and the workaround. It contains a sequential workflow console app with a parallel activity and a series of custom activities, each with a dependency property of a different type (int, string, Person, bool and a WeekDay enum).

The code to do the activity binding creates a new ActivityBind object, sets its Name and Path properties to the workflow type and property, and then calls SetBinding on the activity, passing in the static dependency property we’re binding to and the ActivityBind object.

// TODO: Call this from workflow ctor
ActivityBind boolActivityBind = new
ActivityBind();
void BindBoolActivity()
{
    boolActivityBind.Name = “SampleWorkflow”;
    boolActivityBind.Path = “Result”;
    this.getBoolActivity1.SetBinding
    (GetBoolActivity.ResultProperty,
    ((ActivityBind)(boolActivityBind)));
}

Lastly, you’ll need to call this method from the constructor of the workflow. The project has code in runtime’s WorkflowCompleted event handler that iterates the workflow’s OutputParameters collection, printing out the property name and resulting value. The glitch can put you in a real bind, but I hope this code helps you work around it. J

About Tony Sneed

Married with three children.
This entry was posted in Technical. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s