如何编写包含“主体块”的自定义 WorkFlow 4 代码活动?

发布于 2024-09-06 22:36:15 字数 102 浏览 5 评论 0原文

这可能吗?我知道这是针对 MS 的,因为他们有 WF 活动包,但我不确定它是如何完成的。如果能够使用带有 Body 块的活动来插入其他活动、按钮等,那就太好了。如果不是太麻烦和/或耗时的话。

Is this possible? I know it is for MS since they have WF activity packs but I'm not sure how it's done. It would be nice to be able to have Activities with Body blocks to insert other activities, buttons, etc. If not too much trouble and/or time consuming that is.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

人生百味 2024-09-13 22:36:15

如果您遵循一些规则,这很容易。下面是一个具有子项的 NativeActivity 示例:

[Designer(typeof(MyActivityDesigner)), ContentProperty("Child")]
public sealed class MyActivity : 
    NativeActivity, IActivityTemplateFactory
{
    // this "activity delegate" holds our child activity
    public ActivityAction Child { get; set; }

    // may be necessary to do this
    protected override void 
        CacheMetadata(NativeActivityMetadata metadata)
    {
        metadata.AddDelegate(Child);
    }

    protected override void 
        Execute(NativeActivityContext context)
    {
        // do some work here, then
        context.ScheduleAction(Child);
    }

    // better to use a template factory than a constructor to do this!
    Activity IActivityTemplateFactory
        .Create(System.Windows.DependencyObject target)
    {
        return new MyActivity
        {
            // HAVE to have this set, or it fails in the designer!
            Child = new ActivityAction()
        };
    }
}

请注意以下几点: 我们使用 Activity Delegate 类型来保存我们的子项。其次,我们实现 IActivityTemplateFactory 来为设计器配置我们的活动。这样做总是比在构造函数中设置东西更好/更稳定。我们将绑定到委托的属性,因此我们必须设置一个实例;否则绑定会失败。

当我们执行时,您所要做的就是在适当的时候安排您的孩子并返回。当然,你不应该阻止。

然后,在设计器中,您将像这样绑定到 Child:

<sap:WorkflowItemPresenter
    HintText="Add children here!"
    Item="{Binding Path=ModelItem.Child.Handler}" />

Its easy enough if you follow a few rules. Here's an example of a NativeActivity that has a child:

[Designer(typeof(MyActivityDesigner)), ContentProperty("Child")]
public sealed class MyActivity : 
    NativeActivity, IActivityTemplateFactory
{
    // this "activity delegate" holds our child activity
    public ActivityAction Child { get; set; }

    // may be necessary to do this
    protected override void 
        CacheMetadata(NativeActivityMetadata metadata)
    {
        metadata.AddDelegate(Child);
    }

    protected override void 
        Execute(NativeActivityContext context)
    {
        // do some work here, then
        context.ScheduleAction(Child);
    }

    // better to use a template factory than a constructor to do this!
    Activity IActivityTemplateFactory
        .Create(System.Windows.DependencyObject target)
    {
        return new MyActivity
        {
            // HAVE to have this set, or it fails in the designer!
            Child = new ActivityAction()
        };
    }
}

Note a few things: We use an Activity Delegate type to hold our child. Second, we implement IActivityTemplateFactory to configure our activity for the designer. Its always better/more stable to do this than set stuff up in the constructor. We will be binding to a property of the delegate, so we have to set an instance; otherwise the binding will fail.

When we execute, all you have to do is schedule your child when appropriate and return. You shouldn't block, of course.

Then, in the designer, you'd bind to Child like this:

<sap:WorkflowItemPresenter
    HintText="Add children here!"
    Item="{Binding Path=ModelItem.Child.Handler}" />
梦里梦着梦中梦 2024-09-13 22:36:15

Bruce Bukovics 的 Pro WF : Windows Workflow in .Net 4 一书也有很多示例。您可能想检查一下。

The Pro WF : Windows Workflow in .Net 4 book by Bruce Bukovics also has lots of examples. You might want to check that out.

太阳公公是暖光 2024-09-13 22:36:15

您需要从 NativeActivity 而不是 CodeActivity 开始。 NativeActivity 允许您通过其执行上下文来安排子活动。 NativeActivity 没有模板,您只需创建一个类并从 NativeActivity 派生即可。

You need to start with a NativeActivity instead of a CodeActivity. The NativeActivity lets you schedule child activities through its execution context. There is no template for the NativeActivity, instead you just create a class and derive from NativeActivity.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文