共用方式為


使用自訂活動配合工作流程標記

如果您在工作流程標記程式碼中使用自訂活動,則必須有包含這些自訂活動的組件,而編譯時會在您的主機工作流程程式碼中參考這些自訂活動。 若要這麼做,則必須透過您程式碼中的型別提供者參考包含您自訂活動的組件,如下列範例所示:

// Add referenced assemblies to the TypeProvider.
TypeProvider typeProvider = new TypeProvider(null);
typeProvider.AddAssembly(typeof(CustomActivity).Assembly);
workflowRuntime.AddService(typeProvider);
' Add referenced assemblies to the TypeProvider.
Dim typeProvider as New TypeProvider(nothing)
typeProvider.AddAssembly(GetType(CustomActivity).Assembly)
workflowRuntime.AddService(typeProvider)

此外,如果您使用命令列公用程式 wfc.exe 編譯工作流程,則包含該自訂型別的組件必須新增至您主應用程式碼中的 ReferencedAssemblies,如下列範例所示:

// Create a string array with all the assemblies you need to compile your workflow.
String [] assemblyNames = { "CustomWorkflowAssembly.dll" }
WorkflowCompilerParameters parameters = new WorkflowCompilerParameters(assemblyNames);

// Add the path to your referenced assembly to the collection.
parameters.ReferencedAssemblies.Add(typeof(CustomActivity).Assembly.Location);
' Create a string array with all the assemblies you need to compile your workflow.
Dim assemblyNames as String () = { "CustomWorkflowAssembly.dll" }
Dim parameters as New WorkflowCompilerParameters(assemblyNames)

' Add the path to your referenced assembly to the collection.
parameters.ReferencedAssemblies.Add(GetType(CustomActivity).Assembly.Location)

您也必須將 clr-namespace 值新增至您的工作流程標記檔案,如下列範例所示:

xmlns:ns0="clr-namespace:XamlWithRules;Assembly=XamlWithRules, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"

下列範例說明完整的工作流程標記檔案,此檔案以 CustomActivity activity 的單一執行個體宣告簡單的循序工作流程。

<SequentialWorkflowActivity x:Class="XAMLWorkflow.Workflow1" x:Name="Workflow1" xmlns:ns0="clr-namespace:BusinessActivities;Assembly=CustomActivityAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml" xmlns="https://schemas.microsoft.com/winfx/2006/xaml/workflow">
<ns0:CustomActivity x:Name="CustomActivity1"/>
</SequentialWorkflowActivity>

請參閱

概念

使用工作流程標記

Footer image

Copyright © 2007 by Microsoft Corporation. All rights reserved.