Host workflow designer (2)

Source: Internet
Author: User

Previous: Host workflow designer (1)

Next, the previous article said that a workflowloader class has been defined to import and export workflows. Next we will complete the work of the workflow designer.
This chapter describes how to use the workflowview class to present a workflow designer on the UI.
First, we create an instance of designsurface:

Designsurface = new designsurface ();

As mentioned earlier, this class is responsible for UI rendering. This class serves as a service container and uses the classic service/component model of Microsoft, it loads various services required by the UI rendering designer. We can obtain a designer Host object from it, which is an idesignerhost interface, then obtain the workflow designer in the host from this host. For details about the designer's host structure, see msdn. Workflowloader loader = new workflowloader ();
Loader. xoml = xomlfile;
Designsurface. beginload (loader );

Idesignerhost designerhost = designsurface. getservice (typeof (idesignerhost) as idesignerhost;

Irootdesigner rootdesigner = designerhost. getdesigner (designerhost. rootcomponent) as irootdesigner;

The irootdesigner interface provides us with a getview method. By calling this method, we get a workflowview object, which is a control object. We put this control in the UI of our program, in this way, a workflow designer is hosted by us, and the current workflow designer presents the xomlfile (a string type variable that stores a workflow file path) in the code above) the defined workflow. The previous article describes how the workflowloader class imports and exports the xoml file.
As mentioned in the previous article, our designer is for customers, while the top of the designer in vs is specialized words such as "sequential Workflow" and "state machine Workflow, therefore, we must turn it into the defined text. At the beginning, I always thought that this title should exist in attributes such as the title of workflowview, however, after careful research, I found that the problem was not that simple. Microsoft's design was much more flexible than I thought!
The title of the designer is not determined by the designer object, but by the workflow loaded into the workflowview. All activity objects in the framework can apply the designerattribute feature (sequentialworkflowactivity also inherits the activity ), we all know that the control class can also use this feature to affect the design appearance of the control, while the workflow designer also does this. we can define a design class to customize the design appearance of the workflow, let's take a look at the definition of a designerattribute constructor: Public designerattribute (type designertype, type designerbasetype );

The first parameter is the type of the design class, and the base type of the design class of the second function. According to msdn, the base class of the workflow object is irootdesigner. For a workflow, we can use the class inherited from sequentialworkflowrootdesigner to construct our design class. For activities, we can inherit from activitydesigner. Of course, sequentialworkflowrootdesigner also inherits from activitydesigner. The reason why sequentialworkflowrootdesigner is used is to allow us to get more customizable meanings for the workflow. After inheriting sequentialworkflowrootdesigner, we can rewrite the header attribute to change the workflow designer title. The activitydesigner class also has many attributes that allow us to customize the design appearance, for example, if you want to write a help prompt where you can drag the workflow, you can rewrite the helptext attribute. As mentioned above, you want to disable view sequentialworkflow when you click the workflow start arrow, view cancel handler and view fault handlers. We can rewrite the showsmarttag attribute so that it can always return false, we can also rewrite the initialize method to perform some operations or customize some actions during activity loading. The following is an example of a design class:

Public class customsequentialworkflowdesigner: sequentialworkflowrootdesigner
{
Private string m_text = NULL;

Protected override sequentialworkflowheaderfooter Header
{
Get
{
Base. header. Text = "My Workflow ";

Return base. header;
}
}


Protected override void initialize (system. workflow. componentmodel. Activity activity)
{

This. helptext = "Drag and Drop activity from toolbox to here ";
}

Protected override bool showsmarttag
{
Get
{
Return false;
}
}
}

I believe that you have hosted a workflow designer of your own. Next we will talk about the definition of the Toolbox and other related content.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.