by Raza
24. April 2008 20:15
In the first part we looked at what WF was and what would the simplest workflow would look like in code. Let's move on and use the tools that WF is meant to be used with. First of all, WF follows the same principles you find in other technologies that come with .Net 3.0, especially the Markup + Code = Application thing. You can completely code the workflow or you could break it up into code and markup. The markup being XAML.
I will create a simple workflow called, you guessed correctly, SimpleWorkflow. Also I am using VS 2008, so some screenshots may look slightly different than VS 2005.
If you right click the project and add new item, select workflow you see a number of options. Among them you have sequential and state workflow with code and sequential and state workflow with code separation. We select the sequential workflow with code separation meaning we generate a XAML file and a code behind file.
Workflow designer pops up. Let's drop a code activity in the designer and add some code to it, by double clicking the activity.


Now the workflow is ready, but we chose the empty project for workflow so we don't have a code that host's this workflow. Let's add a class with the main function and add the hosting code too.

Running this code should give us the obvious result.

Now coming back to the code/XAML separation thing. This time we created one such workflow so let's look into that separation.

As you can see the XAML file has the extension xoml here (interesting!) and code has the usual one. If you double click the xoml file then it would open the designer, so you need to do a right click and open with the XML editor. Then you see this (slightly reformatted to fit the screen).

It should be quite obvious how the markup is composed and how it links with the code. If you have worked with ASP.Net then it pretty much the same deal. This concludes the second part. In the next part we will look at using some simple activities.