如何编写包含“主体块”的自定义 WorkFlow 4 代码活动?
这可能吗?我知道这是针对 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您遵循一些规则,这很容易。下面是一个具有子项的 NativeActivity 示例:
请注意以下几点: 我们使用 Activity Delegate 类型来保存我们的子项。其次,我们实现 IActivityTemplateFactory 来为设计器配置我们的活动。这样做总是比在构造函数中设置东西更好/更稳定。我们将绑定到委托的属性,因此我们必须设置一个实例;否则绑定会失败。
当我们执行时,您所要做的就是在适当的时候安排您的孩子并返回。当然,你不应该阻止。
然后,在设计器中,您将像这样绑定到 Child:
Its easy enough if you follow a few rules. Here's an example of a NativeActivity that has a child:
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:
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.
您需要从 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.