WorkflowDesignerLoader.AddActivityToDesigner(Activity) 方法

定义

当将活动添加到父活动集合中后,即会将该活动添加到设计器宿主。

public:
 void AddActivityToDesigner(System::Workflow::ComponentModel::Activity ^ activity);
public void AddActivityToDesigner (System.Workflow.ComponentModel.Activity activity);
member this.AddActivityToDesigner : System.Workflow.ComponentModel.Activity -> unit
Public Sub AddActivityToDesigner (activity As Activity)

参数

activity
Activity

要添加的 Activity

示例

下面的示例演示如何将 CodeActivity 添加到设计器。 在使用 AddActivityToDesigner 方法将活动添加到设计器之前,首先将该活动添加到工作流中根活动的 Activities 集合中。

public void AddCodeActivityToDesigner()
{
    WorkflowDesignerLoader loader = GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader;
    if (loader == null)
        return;

    IDesignerHost designerHost = (IDesignerHost)GetService(typeof(IDesignerHost));
    CompositeActivity rootActivity = designerHost.RootComponent as CompositeActivity;

    CodeActivity codeActivity = new CodeActivity();
    rootActivity.Activities.Add(codeActivity);
    loader.AddActivityToDesigner(codeActivity);
    return;
}
Public Sub AddCodeActivityToDesigner()

    Dim loader As WorkflowDesignerLoader = CType(GetService(GetType(WorkflowDesignerLoader)), WorkflowDesignerLoader)
    If loader Is Nothing Then Return
    Dim designerHost As IDesignerHost = CType(GetService(GetType(IDesignerHost)), IDesignerHost)
    Dim rootActivity As CompositeActivity = CType(designerHost.RootComponent, CompositeActivity)
    Dim codeActivity As New CodeActivity()
    rootActivity.Activities.Add(codeActivity)
    loader.AddActivityToDesigner(codeActivity)
    Return
End Sub

适用于