Welcome to MSDN Blogs Sign in | Join | Help

Mark Schmidt's Abode

On Programming, Writing, Gaming, Fitness, Life

News

  • Have a Question?

    Click here to chat with me

    XBox Live GamerTag


    Twitter



    The Mark Cam


    My MoBlog

    www.flickr.com
    This is a Flickr badge showing public photos from codepunk. Make your own badge here.

    Community-Credit

Programmatically add an activity to the WF designer

Here's a quick code snippet o' the day. If you're hosting the WF designer in an application and want to programmatically add an activity to the designer view, you can use the following code. Basically, grab the IDesignerHost service from your WorkflowView object (the call to GetService below calls the WorkflowView.GetService method and returns the service as an IServiceProvider). Use the IDesignerHost service to get the RootComponent and add your new activity it. For simplicity, we just add a CodeActivity as a child though you can certainly walk the activity tree and insert it wherever you need to. Once this is done, call the AddActivityToDesigner method defined in your WorkflowDesignerLoader object and you're good to go.

public void AddCodeActivityToDesigner()

{

    WorkflowDesignerLoader loader =

        GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader;

    if (loader == null)

        return;

 

    IDesignerHost designerHost = (IDesignerHost)GetService(typeof(IDesignerHost));

    CompositeActivity rootActivity = designerHost.RootComponent as CompositeActivity;

 

    CodeActivity codeActivity = new CodeActivity();

    rootActivity.Activities.Add(codeActivity);

    loader.AddActivityToDesigner(codeActivity);

    return;

}

Posted: Wednesday, August 09, 2006 3:00 PM by markhsch

Comments

No Comments

Leave a Comment

(required) 

(required) 

(optional)

(required) 

  
Enter Code Here: Required

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker