There are two types of properties in the activity Property Window. One is the common property mentioned in section 2nd, and the other is the property of the event type. You can use this property to create an event. For example, you can use the "executecode" property of the Code activity to create an event. developers can perform corresponding business operations in the event. The method for creating an event type attribute in a custom activity is basically the same as that for creating a common attribute. The "dependencyproperty" attribute is also used to manage the attribute of the event type, the corresponding property type is not "string" or "int", but an attribute of the "event" type. The Code is as follows.
Public static dependencyproperty printevent = dependencyproperty. Register ("print", typeof (eventhandler), typeof (activity1 ));
[Description ("print a string")]
[Browsable (true)]
Public event eventhandler print
{
Add {
Base. addhandler (activity1.printevent, value );
}
Remove
{
Base. removehandler (activity1.printevent, value );
}
}
The preceding procedure defines an event type attribute, but this attribute cannot be executed. You must reload the "execute" method of the parent class and use "raiseevent" to load the corresponding "dependencyproperty" attribute. The Code is as follows.
Protected override activityexecutionstatus execute (activityexecutioncontext context)
{
Base. raiseevent (activity1.printevent, this, eventargs. Empty );
Return activityexecutionstatus. closed;
}
Create custom Activity
You can use the preceding code to create a custom activity. After compilation, add the activity to the workflow design interface, as shown in figure 1, in the Properties window, use the "print" attribute to create an event "exeprint" for execution. The Code is as follows.
Private void exeprint (Object sender, eventargs E)
{
Console. Write ("the method printevent defined in the Custom activity is executed! \ R \ n ");
}
Figure 1
Run the workflow project. As shown in figure 2, the event "exeprint" created by the user through the attribute "print" is executed.
Figure 2