views:

622

answers:

3

I want to better understand the capabilities and limitations of what can be done with custom activities in WF 4.0 at design time. More specifically, what we can do in a custom activity such that we can allow the designer to interact in a customized way at the design time for specifying details/data about an activity.

For example, I would like to create an activity A, and when the workflow designer places that activity in a workflow in the designer (either Visual Studio designer or a re-hosted designer in a separate application), a .NET dialog can be shown that lets the user enter data (e.g. specify a file through Open File dialog) and validates input data i.e. runs some code whenever a particular text box is focused or data entered (event handlers).

Can this be done and stored in the workflow XAML file?

Please note that all this capability is required in a workflow designer when a workflow is actually being designed.

Thanks.

+1  A: 

The WF4 designer is quite capable. You can add controls to the designer allowing the end user to interact with the design surface directly without using the property sheet. You can also add validation to activities to check if the data entered is acceptable or not. All of this is done at the activity level in C# or VB code, not at the workflow level. I am not sure about events when an activity is dropped but believe they are also supported (they where in Wf3 at least and I would expect that to be carried forward.

Maurice
+1  A: 

This video talks about how to create custom activities (with textbox) so that you can put the values in design time.. hope this helps u..

http://bloggersguides.net/media/p/188.aspx

Jeeva S
+1  A: 

There are a few ways you could hook in to event notifications when an activity is added to your workflow.

The first one is listening to the TextChanged event on the WorkflowDesigner class (Beta1) or I think there is going to be a ModelChanged event (in Beta2), which is more reliable. This is a notification that something has changed in your workflow. Not anything in particular, just something, but you could use this as a trigger to traverse your workflow and look for new, unconfigured activities.

A second possibility is taking advantage of the fact that each ModelItem (which is the design-time wrapper for an activity) implements INotifyPropertyChanged. Instead of listening for changes in the whole workflow, you could listen for changes on specific properties, such as the 'Body' of a While activity - then when the property gets initialized to hold a new activity, respond to the change.

A third possibility is that the activity you are interesting in has a custom designer (which you write) - and it sounds like this scenario matches what you are thinking of. Here you can fully customize the appearance of your activities. The custom designer is really just a WPF control. You can use the same events and databinding and validation techniques that apply when designing a WPF application, or respond to normal WPF events. You can certainly pop up dialogs if you wish to.

As for being stored in XAML files, of course custom activities are saved in XAML files along with all their configured properties - just like regular activities. When you want to load the XAML file again, you do need to provide context information about the assemblies holding the activities referenced by the XAML file. In VS this is as easy as adding assembly references, in rehosting scenario you would write a little code to do this.

You might like to find more about this or ask similar questions on the .NET Framework 4: Workflow Foundation - Beta 1 Forum

Tim Lovell-Smith