Share via


Workflow Foundation (WF 4.5) - Designer Improvements

.NET 4.5 has introduced some great new features to improve the usability of the Workflow designer. If you’re rehosting the designer outside of Visual Studio then you can take advantage of most of these features very easily which is what I have done with Workflow Studio. If you’ve read my previous post you’ll know that Workflow Studio is a rehosted WF designer implementation that allows you to execute and debug workflows in a windowing environment that supports docking and pinning (courtesy of AvalonDock). You can download the latest version here.

New Designer Features

I’m not going to go into the full details of these new features in this post as there’s a comprehensive description in this MSDN documentation which also goes into the runtime improvements. However here’s a quick summary:

· Pan Mode – navigate large workflows by switching to pan mode then dragging the designer surface rather than using scroll bars

1

· Multi Select – select multiple activities by dragging a box around them or holding down CTRL whilst clicking individual activities

2

· Auto Connect and Auto Insert – add connections between flowchart nodes automatically. Also, dropping an activity on an existing connection inserts the new activity between the two nodes

3

· Designer Annotations – add notes to individual activities

4

 

· Auto Surround With Sequence – for parent activities that only take a single child, the auto surround feature inserts a sequence automatically as a container so that multiple children can be added. Here the sequence has been added after dragging the second WriteLine activity in the body of the DoWhile activity

6

· Delete context menu in variable and argument designer – delete variables and arguments from a context menu rather than having to press the delete key

7

· Display name of FlowSwitch and FlowDecision is editable – allow a display name to be entered for these activities to make flow charts more readable

8

· Unconnected flow chart nodes cause validation errors – by setting the ValidateUnconnectedNodes property on the Flowchart activity, unconnected flow chart nodes will now raise a validation error

9

Enabling the Features

Enabling these new features is simple. Just set DesignerConfigurationService.TargetFrameworkName to indicate .NET Framework 4.5. Here’s how it’s done in Workflow Studio:

 

 this.workflowDesigner.Context.Services.GetService<DesignerConfigurationService>().TargetFrameworkName = 
    new System.Runtime.Versioning.FrameworkName(".NETFramework", new Version(4, 5))

This enables all the previously mentioned features. The opt-in approach here preserves backwards compatibility ensuring these features don’t suddenly become available in scenarios where you wouldn’t want them to. You can selectively disable these features by setting individual properties of DesignerConfigurationService.

Unfortunately not all new designer features are available if you’re rehosting. Sadly, support for C# expressions outside of Visual Studio is not supported. Also designer search features (Quick Find and Find In Files) are excluded.

One feature I haven’t mentioned yet that requires a bit more effort to implement is Outline View. This view allows you to navigate hierarchical workflows by viewing the workflow as a tree in a separate window. Selecting an activity in the designer highlights the node in the tree and vice versa.

Here’s how it looks in Workflow Studio:

10

To get an instance of an outline view you simply use the WorkflowDesigner.OutlineView property. The returned UIElement object can then be added to a UI container of your choice. If you have looked at previous examples or rehosting then this is no different to displaying the property grid returned by WorkflowDesigner.PropertyInspectorView.

Loading XAML From Untrusted Sources

Prior to 4.5 it was possible to load XAML from an untrusted source (for example a network location or downloaded from the Internet). If you attempt to do this with 4.5 then by default you’ll get the following exception:

System.Security.SecurityException occurred

The file <path> may have come from a location that isn't fully trusted. It could present a security risk by opening the file that could cause damage to your computer or compromise your private information.

In order to specify that you are happy to accept the risk of loading such a file, the DesignerConfigurationService.LoadingFromUntrustedSourceEnabled property must be set to true. Now rather than hardcode the setting of the property in Workflow Studio, a new configuration item has been added to Workflow Studio’s App.config file to allow you to make that choice. Simply change it to true to allow untrusted sources:

Installing AvalonDock

As mentioned previously, Workflow Studio is dependent on AvalonDock to implement all docking and pinning functionality and you need to install this before you build the Workflow Studio solution.

AvalonDock is not distributed with Workflow Studio so you need to download it independently. This version of Workflow Studio has been developed with version 1.3.3571 of AvalonDock so please ensure you install this version. The steps are simple:

  1. Download AvalonDock version 1.3.3571 from https://avalondock.codeplex.com/releases/48794/download/131885
  2. Run the installer. This will GAC the AvalonDock assembly.
  3. Build the solution. You should not need to modify any references.

Conclusion

As you can see there are some long awaited enhancements here and you can take advantage of them immediately in your own WF rehosted designer implementation when you switch to .NET 4.5 or by downloading Workflow Studio for .NET 4.5 from here.

Happy designing …

Written by Christopher Owczarek

(I’d like to thank Hani Khoshdel-Nikkhoo for originally supplying details of implementing these new features in absence of any official documentation).

Comments

  • Anonymous
    April 24, 2013
    I'm trying to customize the Workflow Studio and I wonder how I can modifiy the tool in order to start accepting C# expressions instead or VB expressions. thanks, Santiago

  • Anonymous
    June 10, 2013
    The comment has been removed

  • Anonymous
    July 22, 2013
    Sorry for your frustration. Unfortunately it is not possible to use C# expressions in a rehosted designer. This is because this functionality is dependent on Visual Studio. See msdn.microsoft.com/.../jj591618.aspx.

  • Anonymous
    October 07, 2013
    Hi all! How I can add StateMachine tools to WF studio? Please,help!

  • Anonymous
    October 08, 2013
    Hi Damir, Simply add the following to the InitialiseToolbox method in MainWindowViewModel class: this.AddCategoryToToolbox(                "State Machine",                new List<Type>                {                    typeof(State),                    typeof(StateMachine),                    typeof(FinalState),                }); (consider adding "State Machine" literal to the Resources.resx file as this is best practice). Also, modify IsValidToolboxActivity method (in same class) to return activityType.IsPublic && !activityType.IsNested && !activityType.IsAbstract                && (typeof(Activity).IsAssignableFrom(activityType) || typeof(IActivityTemplateFactory).IsAssignableFrom(activityType) || typeof(FlowNode).IsAssignableFrom(activityType) || typeof(State).IsAssignableFrom(activityType) || typeof(FinalState).IsAssignableFrom(activityType)); This should have been added to the latest version of Workflow Studio as the state machine activity became generally available in WF 4.5 but got missed. Hope this helps.

  • Anonymous
    May 31, 2015
    What about intellisense?  Is it not possible in Workflow Studio?