Saturday, February 27, 2010

WF 4.0 Custom Activity Designer

In this blog post i am going to build Custom Activity Designer for the Custom Activity which I created in my previous blog post.  [http://mstecharchitect.blogspot.com/2010/02/wf-40-custom-code-activity-vsnet-2010.html]. 

Activity Designer:

The WF 4.0 Activity Designer is based on WPF ( Windows Presentation Foundation) which means we have all the power of WPFs which is Rich UI , Styling, Data binding,Triggers etc., for our Custom Activity. In addition to this WF also provides some user controls that you can use in your Activity Designer to simplify the task of displaying an individual child activity, or a collection of activities.

The four primary controls are:

  • ActivityDesigner – root WPF control used in activity designers
  • WorkflowItemPresenter – used to display a single Activity
  • WorkflowItemsPresenter – used to display a collection of child Activities
  • ExpressionTextBox – used to enable in place editing of expressions such as arguments.
  • Now we are going to add new Item  template called [Activity Designer] to our Custom Activity project  as shown below.

    image

    After adding Activity Designer template we need to Create User Interface in XAML .

    image

    Here i am using ActivityDesigner item template to create a UI for custom activity because i have only one Activity in my project. Suppose if you have more number of custom activities you can use WF4 ActivityDesignerLibrary project template.  Once we have added the Designer ,now we are ready to  customize the look and feel of out custom activity by laying out how to display data and visual representations of child activities.  Within the designer you have access to a ModelItem that is an abstraction over the actual activity, and surfacing all properties of the activity. 

    Once we build the UI now we need to attach designer to our Custom Activity class as shown below. 

    image

    Now add Custom Activity project as a Reference in Main [hosting] Workflow project & Compile the Custom Activity project. Now this custom activity will appear in Toolbox. now Drag and drop and set the properties for the custom activity. 

    image

    Since this custom activity returns the List of File names from the given input Directory to store the output result we need to create Workflow variable then to loop through the List of File names  add ForEach<String> activity and print the file name using WriteLine Activity. 

    image

    image

    image 

    Now Hit F5 and Run the Main Work Flow project. you will see the Files listed form the given directory as shown below.

    image

    For More Info Please Refer the following URI: http://msdn.microsoft.com/en-us/library/ee342461.aspx.

    Nandri(Thanks)

    SreenivasaRagavan.

    3 comments:

    @ said...
    This comment has been removed by the author.
    ADmin said...

    To succeed, at secondary right here school and in tertiary think about you should ace exposition composing.

    Unknown said...

    Thank you for this fantastic and needful read. I was very encouraged to find this site.Thanks a lot.