.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
· Multi Select – select multiple activities by dragging a box around them or holding down CTRL whilst clicking individual activities
· 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
· Designer Annotations – add notes to individual activities
· 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
· Delete context menu in variable and argument designer – delete variables and arguments from a context menu rather than having to press the delete key
· Display name of FlowSwitch and FlowDecision is editable – allow a display name to be entered for these activities to make flow charts more readable
· 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
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:
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:
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:
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:
<add key="LoadingFromUntrustedSourceEnabled" value="true"/>
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:
- Download AvalonDock version 1.3.3571 from http://avalondock.codeplex.com/releases/48794/download/131885
- Run the installer. This will GAC the AvalonDock assembly.
- Build the solution. You should not need to modify any references.
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).