Custom activity designers in Workflow Foundation 3.5: How do they work?

Posted by stakx on Stack Overflow See other posts from Stack Overflow or by stakx
Published on 2010-04-25T09:51:35Z Indexed on 2010/04/25 9:53 UTC
Read the original article Hit count: 322

Intent of this post:

I realise that Workflow Foundation is not extremely popular on StackOverflow and that there will probably be not many answers, or none at all. This post is intended as a resource to people trying to customise workflow activities' appearance through custom designer classes.


Goals:

I am attempting to create a custom designer class for Workflow activities to achieve the following:

  1. Make activities look less technical. For example, I don't necessarily want to see the internal object name as the activity's "title" -- instead, I'd like to see something more descriptive.

  2. Display the values of certain properties beneath the title text. I would like to see some properties' values directly underneath the title so that I don't need to look somewhere else (namely, at the Properties window).

  3. Provide custom drop areas and draw custom internal arrows. As an example, I would like to be able to have custom drop areas in very specific places.


What I found out so far:

I created a custom designer class deriving from SequentialActivityDesigner as follows:

[Designer(typeof(SomeDesigner))]
public partial class SomeActivity: CompositeActivity
{
    ...
}

class PlainDesigner : SequentialActivityDesigner
{
    ...
}

Through overriding some properties and the OnPaint method, I found out about the following correspondences between the properties and how the activity will be displayed:

Diagram showing the relationships between some properties of a SequentialActivityDesigner and the displayed activity.
Figure 1. Relationship between some properties of an SequentialActivityDesigner and the displayed activity.

Possible solutions for goal #1 (make activities look less technical) and goal #2 (display values of properties beneath title text):

  • The displayed title can be changed through the Title property.

  • If more room is required to display additional information beneath the title, the TitleHeight property can be increased (ie., override the property and make it return base.TitleHeight + n, where n is some positive integer).

  • Override the OnPaint method and draw additional text in the area reserved through TitleHeight.


Open questions:

  • What are the connectors, connections, and connection points used for? They seem to be necessary, but for what purpose?

  • While the drop targets can be got through the GetDropTargets method, it seems that this is not necessarily where the designer will actually place dropped activities. When an activity is dragged across a workflow, the designer displays little green plus signs where activities can be dropped; how does it figure out the locations of these plus signs?

  • How does the designer figure out where to draw connector lines and arrows?

© Stack Overflow or respective owner

Related posts about .net-3.5

Related posts about workflow-foundation