我正在學習有關Windows Workflow Foundation的4,並試圖創建下列程序:引用時XAML工作流
using System;
using System.Activities.XamlIntegration;
using System.Linq;
using System.Activities;
using System.Activities.Statements;
using System.Reflection;
using System.Xaml;
namespace BranchedActivities
{
class Program
{
static void Main(string[] args)
{
Activity wf = ActivityXamlServices.Load(@"C:\...\Workflow1.xaml");
WorkflowInvoker.Invoke(wf);
Console.ReadKey();
}
}
}
Workflow1包括一個單一的行動,呼籲活動1。 Activity1.xaml由單個Writeline組成。
當我將工作流加載爲編譯的Activity(通過使用「Activity wf = new Workflow1()」),程序加載完美。 當我嘗試加載活動的XAML(如上面的代碼)時,獲取異常:無法創建未知類型'{clr-namespace:} Activity1'。
我想我不得不以某種方式加載另一個xaml文件,雖然我很困難如何。
供您參考.... Workflow1.xaml:
<Activity mc:Ignorable="sap" x:Class="Workflow1" sap:VirtualizedContainerService.HintSize="262,240" mva:VisualBasic.Settings="Assembly references and imported namespaces for internal implementation" xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mv="clr-namespace:Microsoft.VisualBasic;assembly=System" xmlns:mva="clr-namespace:Microsoft.VisualBasic.Activities;assembly=System.Activities" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:s1="clr-namespace:System;assembly=System" xmlns:s2="clr-namespace:System;assembly=System.Xml" xmlns:s3="clr-namespace:System;assembly=System.Core" xmlns:sad="clr-namespace:System.Activities.Debugger;assembly=System.Activities" xmlns:sap="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation" xmlns:scg="clr-namespace:System.Collections.Generic;assembly=System" xmlns:scg1="clr-namespace:System.Collections.Generic;assembly=System.ServiceModel" xmlns:scg2="clr-namespace:System.Collections.Generic;assembly=System.Core" xmlns:scg3="clr-namespace:System.Collections.Generic;assembly=mscorlib" xmlns:sd="clr-namespace:System.Data;assembly=System.Data" xmlns:sl="clr-namespace:System.Linq;assembly=System.Core" xmlns:st="clr-namespace:System.Text;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:">
<Sequence sad:XamlDebuggerXmlReader.FileName="C:\...\Workflow1.xaml" sap:VirtualizedContainerService.HintSize="222,200">
<sap:WorkflowViewStateService.ViewState>
<scg3:Dictionary x:TypeArguments="x:String, x:Object">
<x:Boolean x:Key="IsExpanded">True</x:Boolean>
</scg3:Dictionary>
</sap:WorkflowViewStateService.ViewState>
<local:Activity1 sap:VirtualizedContainerService.HintSize="200,22" />
</Sequence>
</Activity>
Activity1.xaml
<Activity mc:Ignorable="sap" x:Class="Activity1" sap:VirtualizedContainerService.HintSize="273,240" mva:VisualBasic.Settings="Assembly references and imported namespaces for internal implementation" xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mv="clr-namespace:Microsoft.VisualBasic;assembly=System" xmlns:mva="clr-namespace:Microsoft.VisualBasic.Activities;assembly=System.Activities" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:s1="clr-namespace:System;assembly=System" xmlns:s2="clr-namespace:System;assembly=System.Xml" xmlns:s3="clr-namespace:System;assembly=System.Core" xmlns:sad="clr-namespace:System.Activities.Debugger;assembly=System.Activities" xmlns:sap="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation" xmlns:scg="clr-namespace:System.Collections.Generic;assembly=System" xmlns:scg1="clr-namespace:System.Collections.Generic;assembly=System.ServiceModel" xmlns:scg2="clr-namespace:System.Collections.Generic;assembly=System.Core" xmlns:scg3="clr-namespace:System.Collections.Generic;assembly=mscorlib" xmlns:sd="clr-namespace:System.Data;assembly=System.Data" xmlns:sl="clr-namespace:System.Linq;assembly=System.Core" xmlns:st="clr-namespace:System.Text;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Sequence sad:XamlDebuggerXmlReader.FileName="C:\...\Activity1.xaml" sap:VirtualizedContainerService.HintSize="233,200">
<sap:WorkflowViewStateService.ViewState>
<scg3:Dictionary x:TypeArguments="x:String, x:Object">
<x:Boolean x:Key="IsExpanded">True</x:Boolean>
</scg3:Dictionary>
</sap:WorkflowViewStateService.ViewState>
<WriteLine sap:VirtualizedContainerService.HintSize="211,61" Text="Hello World" />
</Sequence>
</Activity>
這對我構建GettingStarted示例WF應用 –
[另一種方法是從dll加載所有已編譯的活動](https://gist.github.com/nickdevereaux/592ddffb38c5697b0c21)。在我的例子中,我有一個只編譯了工作流活動的目錄,但是你可以對任何目錄執行此操作,當然需要更長的時間 –