by Keyvan Nayyeri via Keyvan Nayyeri on 2/13/2007 5:53:15 AM
So far I've discussed about these topics about writing a custom workflow activity:
As I stated in first part there is only one component remained: Designer. In this post I finish this series by discussing about designer component. Designer component is where you can change the visual presentation of an activity. By default Visual Studio applies a pre-defined designer to custom activities that you saw in previous posts but using designer component you can change this designer.
Designer component can be split into two component itself: ActivityDesigner and ActivityDesignerTheme. First component is the main component for designer and second one is used to change the theme of activity (background and foreground colors and ...).
These are steps to create a designer for a custom workflow:
To write a designer theme you must follow these steps:
I prefer to step directly into code and update my sample to show above steps in action.
First I create a new class and name it CustomActivityDesigner and inherit this class from ActivityDesigner.
using System;
using System.Collections.Generic;
using System.Text;
using System.Workflow.ComponentModel.Design;
namespace CustomActivitySample
{
internal sealed class CustomActivityDesigner : ActivityDesigner
}
Now I create another class for my designer theme and name it CustomActivityDesignerTheme and inherit it from ActivityDesignerTheme.
using System.Drawing;
internal sealed class CustomActivityDesignerTheme : ActivityDesignerTheme
After this I create and inherit a constructor for this class and set start and end background colors for my activity theme. Note that here it's possible to set some other properties for activity theme. Final code for my designer theme class looks like this:
public CustomActivityDesignerTheme(WorkflowTheme theme)
: base(theme)
this.BackColorStart = Color.LightCoral;
this.BackColorEnd = Color.LightGreen;
At this point I can go back to my designer class and add an ActivityDesignerTheme attribute to use this designer theme.
[ActivityDesignerTheme(typeof(CustomActivityDesignerTheme))]
Now I can simply implement my logic for main designer component by overriding necessary methods from base class. There are some methods to override but it depends on you (as developer) to choose these methods and customize your designer. A full list of these methods with their description is available on MSDN. For my sample I want to change the activity text and change the position of text rectangle by overriding Initialize() method and TextRectangle property.
protected override void Initialize
(System.Workflow.ComponentModel.Activity activity)
base.Initialize(activity);
this.Text = "KeyvanNayyeri";
protected override Rectangle TextRectangle
get
return new Rectangle(this.Bounds.Right - 55,
this.Bounds.Top - 5, 50, 50);
So as you see in image below, my activity has a new designer.
Full source code for the sample custom workflow activity that I used in my posts is attached to this post and you can download it.
Original Post: How to Write a Designer Component for Custom Workflow Activity
The content of the postings is owned by the respective author. CSharpFeeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on CSharpFeeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.