Windows Workflow Custom Sequence Activity

折月煮酒 提交于 2019-11-29 12:36:39

The "System.Activities.Core.Presentation.SequenceDesigner" designer is already available in WF 4. One can then compose a Sequence activity and use this designer for the outer class.

Here's a working example:

using System.Activities;
using System.Activities.Statements;
using System.Collections.ObjectModel;
using System.ComponentModel;

[Designer("System.Activities.Core.Presentation.SequenceDesigner, System.Activities.Core.Presentation")]
public class MySeq : NativeActivity
{
    private Sequence innerSequence = new Sequence();

    [Browsable(false)]
    public Collection<Activity> Activities
    {
        get
        {
            return innerSequence.Activities;
        }
    }

    [Browsable(false)]
    public Collection<Variable> Variables
    {
        get
        {
            return innerSequence.Variables;
        }
    }

    protected override void CacheMetadata(NativeActivityMetadata metadata)
    {
        metadata.AddImplementationChild(innerSequence);
    }

    protected override void Execute(NativeActivityContext context)
    {
        context.ScheduleActivity(innerSequence);
    }

}

This is forwarding the real behavior on to a private innerSequence, which might make this code seem useless, but note that in the Execute method it gives us a chance to do things before and after execution. If we want to provide customized behavior, we'd have to implement it instead of forwarding to an inner private activity.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!