1

Is it possible to work with a sub-workflow (i.e. subset of the workflow in the designer). For example a sequence, a flowchart, or any activity inside the workflow.

My idea is something like these:

  • Save the subworkflow to a file (for example, save the selected Sequence activity)
  • Load a saved subworkflow and add it into current workflow
  • Add a sub-workflow as an item in toolbox

Are these even possible in WF4?

Louis Rhys
  • 34,517
  • 56
  • 153
  • 221

1 Answers1

1

Sounds very much like your sub worklfows are just composite activities. Doing so is easy if you compile them as they become regular activity types and you can do with them as you like. If you don't want to compile them but use them as XAML files you will need to create a compiled wrapper activity using a DynamicActivity and the ActivityXamlServices. This is needed because activities added to a workflow or shown in the toolbox are always compiled.

Maurice
  • 27,582
  • 5
  • 49
  • 62
  • you're right. composite activity is what I had in mind. How do you save it to a xml? Can I add an Activity loaded from ActivityXamlServices to the toolbox? – Louis Rhys Nov 24 '10 at 09:28
  • You can use ActivityXamlServices to load an instance of an activity/workflow stored in a XAML file. To add it to the toolbox, or a workflow, you need an activity type so that needs to be compiled. – Maurice Nov 24 '10 at 09:31
  • Can I add an activity instance to the workflow with something like this? http://blogs.msdn.com/b/kushals/archive/2009/10/27/adding-activities-on-the-designer-programmatically.aspx Can I save a composite activity to xaml? – Louis Rhys Nov 24 '10 at 13:41
  • Yes and yes :-) Each activity on a workflow is an instance. On the toolbox it is a type though. And if you create an activity using the designer it is a XAML file. Only if you create one through code, CodeActivity or NativeActivity, is there no xaml. – Maurice Nov 24 '10 at 13:50
  • 1
    I mean, can I save a composite activity on runtime to xaml? For example I have a sequence and fill it with several activities. But this is not the whole workflow so I cannot use WorkflowDesigner.Save. Can I save this sequence (and its content) to xaml? – Louis Rhys Nov 24 '10 at 14:48
  • Yes. See http://msmvps.com/blogs/theproblemsolver/archive/2010/08/28/converting-a-c-workflow-into-xaml.aspx – Maurice Nov 24 '10 at 15:09
  • I am getting the error: Type 'System.Activities.Presentation.Model.ModelItemImpl' not visible. If the type is local, please set the LocalAssembly field in XamlReaderSettings. – Louis Rhys Nov 25 '10 at 05:43
  • That is an internal par of WF4 and should not be mentioned in your XAML files. – Maurice Nov 25 '10 at 11:32