在 WF4 中可以通过IActivityTemplateFactory来实现复合活动:
public sealed class CompositeActivity : IActivityTemplateFactory
{
public Activity Create(DependencyObject target)
{
return new Sequence
{
Variables = {
new Variable<string>("MyStringVar"),
new Variable<int>("MyIntegerVar")
},
Activities = {
new WriteLine { Text = "My first activity within the composite" },
new Delay { Duration = new InArgument<TimeSpan>(a => TimeSpan.FromSeconds(5)) },
new WriteLine { Text = "My third activity within the composite" }
}
};
}
}
设计者知道IActivityTemplateFactory,因此它会像任何其他活动一样显示在工具箱上。