Tuesday, April 22, 2008

Browsable Attribute/Property of Custom Activity in ASP.Net Workflow

In continuation with my earlier article Custom Activity in ASP.Net Workflow

1) To add a browsable attribute/property in your custom activity, you have insert following code in your custom activity class:


public static DependencyProperty OwnerNameProperty = DependencyProperty.Register("OwnerName", typeof(string), typeof(MyActivity), new PropertyMetadata(DependencyPropertyOptions.Metadata, new Attribute[] { new ValidationOptionAttribute(ValidationOption.Required) }));

[DescriptionAttribute("OwnerName")]
[CategoryAttribute("Input")]
[BrowsableAttribute(true)]
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
public string OwnerName
{
get
{
return ((string)(base.GetValue(MyActivity.OwnerNameProperty)));
}
set
{
base.SetValue(MyActivity.OwnerNameProperty, value);
}
}

Here the custom property name is “OwnerName”.

2) You can access your property in your custom activity, by simply access it like “this.PropertyName”. E.g,


Console.WriteLine("OwnerName : " + this.OwnerName);

In my case, I have inserted the above code in Activity’s “Execute” method.

3) After doing the required changes. To test your custom property, remove your activity from workflow designer and again Drag-n-Drop in Workflow designer from toolbox. Now to set your property, select the activity in workflow designer. In properties window, you will see your custom property against your custom activity. Here you will see “OwnerName” property in “MyActivity”.



4) After setting the property, rebuild the whole application, i.e. Workflow and Console application project. Run the console application. Following is the output window of console application:


No comments:

Google