Windows Workflow Foundation 4 Create Base Activity

喜欢而已 提交于 2019-12-23 22:22:34

问题


In Windows Workflow Foundation 3.x, you used to be able to create a BaseWorkflow class where you could define some properties in that workflow.

And then when you create a workflow you can say it derives from BaseWorkflow class so it inherits all the properties from the base workflow.

Can we achieve the same thing in Windows Workflow Foundation 4 (WF 4)? Like defining InArgument and OutArgument on a BaseActivity then create another Activity that derives from the BaseActivity.

I tried by modify the XAML from let's say <Activity></Activity> to like <BaseActivity></BaseActivity> ... that was the way we did it in WF 3.x.

It doesn't seem to work in WF 4.


回答1:


Found a solution to this. It's actually quite easy. The class generated by the XAML declaration is marked as partial so you can create a class (also marked partial) for your activity (workflow) base. Then in XAML, just change the class attribute on your activity to the full namespace of the class you just created.

Base Activity Example:

public partial class OurBaseWorkflow : Activity
{
     public InArgument<string> StandardInput { get;set; }
}

XAML example:

<p:Activity x:Class="MyNamespace.OurBaseWorkflow"
            xmlns:s="clr-namespace:System;assembly=mscorlib"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    ...
</p:Activity>

With this method, you can define both in and out arguments on the base class and they show up for your derived activities as well.




回答2:


Yes, you can create a BaseActivity and define its InArguments and OutArguments. You can then create a new class, say Activity1:BaseActivity and it still has BaseActivity's InArguments and OutArguments



来源:https://stackoverflow.com/questions/4620242/windows-workflow-foundation-4-create-base-activity

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