This article is part of a series:
Using the WF designer to compose workflows from other workflows is trivial providing the child workflow has been compiled. Then it’s simply a case of drag and drop. But what about the scenarios where at design time the child workflow is a XAML file that hasn’t been compiled? Perhaps you’re working in a re-hosted designer environment where compilation is not available, or perhaps the XAML files are generated by some tool? Whatever the scenario, currently there’s no design time support to setup the invocation of XAML file based workflows.
In this post I'm going to introduce you to the ExecuteXamlWorkflow custom activity which can be downloaded from here. Once added to your WF designer toolbox the custom activity will allow you to execute a XAML file based child workflow. You simply drag the activity to the designer surface, specify the XAML file and setup its arguments through a simple dialog. At runtime, it executes the specified child workflow through to completion..
The focus has been to provide a designer experience that is as simple as possible for the user. Full validation using the standard WF designer mechanisms is provided. And to improve performance, child workflows are cached once loaded.
The source code solution comes complete with a demo project that shows the ExecuteXamlWorkflow custom activity in action. Open the solution file and within the ExecuteXamlWorkflowDemo project open Demo.xaml which looks like this:
This is the parent workflow that invokes two child workflows Increment.xaml and Multiply.xaml. The parent has three variables; val1, val2 and result. In the loop, val1 and val2 are passed to the child workflows Increment.xaml and are each incremented up to the value of 10 (the use of the Parallel activity is just for fun). Once out of the loop, the two variables are passed to the Multiply.xaml child workflow where the two values are multiplied and passed out into the result variable. Finally the result is output to the console.
Remember the tip about absolute paths? The demo references its child workflows by resolving the environment variable “workflowsdir”. Make sure you define this to point to the demo project directory where Increment.xaml and Multiply.xaml reside.
Hit F5 to run the application. The parent will execute and invoke its children where we should see the value 100 displayed in the console!
In the next post I'll discuss some of the rationale and gotchas behind implementing this solution. If you're new to implementing custom activities and designers then you may find some of this information valuable so hopefully see you then ...
Written by Christopher Owczarek