What Was I Thinking?

Follies & Foils of .NET Development
posts - 94 , comments - 348 , trackbacks - 0

Setting Default Custom Property Values At Design Time

You can easily extend the functionality of the WF designer for your custom activities by rolling your own activity designer.  I've found numerous uses for this including inserting additional activities when a parent composite activity is added to the design surface and setting default property values at design time.

 

When I have an activity whose properties are usually bound to the same value (often a property on my base workflow), I find it useful to extend the designer to create this bindings automatically for me when I drag the activity from the toolbox onto the design surface.

Start with creating your own activity designer and overriding the Initialize method.

 

In this example I'll be creating an activity binding for the PrincipalId property on my RunPublishedWorkflow activity to the value of the PrincipalId on my workflow.

 

protected override void Initialize(Activity activity)
{
  base.Initialize(activity);
  Activity wf = ActivityDesignerHelper.GetRoot(activity) as Activity;
  if (wf != null)
  {
     // Create a binding to the PrincipalId property on the root workflow activity
     ActivityBind bindPrincipalId = new ActivityBind(wf.Name, "PrincipalId");
    // Programmatically set the binding we just created to the
   // PrincipalID Property on this activity 
    activity.SetBinding(RunPublishedWorkflowActivity.PrincipalIdProperty, 
    bindPrincipalId);
  }
}

Don't forget to wire up the custom activity to the new activity designer

[ToolboxBitmap(typeof(RunPublishedWorkflowActivity), "Logo.png")]
[ActivityValidator(typeof(RunPublishedWorkflowActivityValidator))]
[Designer(typeof(RunPublishedWorkflowActivityDesigner), typeof(IDesigner))]
public class RunPublishedWorkflowActivity : Activity

Now when I drag and drop my "RunPublishedWorkflow" activity, my PrincipalId property is already bound to the workflow's principal.

 

autoactbind

Print | posted on Wednesday, December 12, 2007 12:13 PM |

Feedback

No comments posted yet.
Post A Comment
Title:
Name:
Email:
Comment:
Verification:
 

Powered by: