5

Windows Workflow Foundation 4 について学習していて、次のプログラムを作成しようとしました。

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 は、Activity1 を呼び出す単一のアクションで構成されます。Activity1.xaml は、単一の Writeline で構成されています。

ワークフローをコンパイル済みのアクティビティとしてロードすると (「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>
4

3 に答える 3

4

生成された dll を手動で参照する必要があることがわかりました。私が使用した作業コードは次のとおりです。

XamlReader xamlReader;
//Assembly wfAssembly = Assembly.GetExecutingAssembly();
Assembly wfAssembly = Assembly.LoadFile(@"Workflows.dll");
XamlXmlReaderSettings settings = new XamlXmlReaderSettings();
settings.LocalAssembly = wfAssembly;
xamlReader = new XamlXmlReader(@"Workflow.xaml", settings);
Activity wf = ActivityXamlServices.Load(xamlReader);

Visual Studio 自体でワークフローをコンパイルする必要があります。それらがライブラリに入ったら、上記のように参照します。

于 2012-06-29T21:54:46.977 に答える
0

xaml はルーズな xaml ではなく、コード ビハインド (クラス) を含む xaml であるため、xaml を単独でロードすることはできません。

要素x:Class="Activity1"から属性を削除してみてください。 - アクティビティのコード ビハインドにメンバー (メソッド、フィールド、プロパティ) がない場合、コード ビハインドは実際には必要ありません。Activity

(アトリビュートについても同様ですx:Class="Workflow1"。)

編集:

(xmlns:local=または , などの他の名前空間)属性はxmlns:src=、デフォルト ( ) 以外のカスタムまたはシステム名前空間内の型を参照するためにのみ使用されます。xmlns:x=xmlns:srd=xmlns=

xmlns:local="clr-namespace:"どこにもマップされていないため、有効な名前空間マッピングではありません!

ローカル名前空間を 1 か所で使用している<local:Activity1 sap:VirtualizedContainerService.HintSize="200,22" />ため、マッピングが必要ですが、それを修正しすぎる必要があります。(たとえばxmlns:local=MyCompany.MyProject.SubNameSpace、xaml が入っているのと同じ DLL を参照していると仮定します。)

xaml を Loose xaml としてロードする場合は、アセンブリ名も定義に追加する必要があります。xmlns:mms=MyCompany.MyProject.SubNameSpace;AssemblyName-localルース xaml にはローカル ns がないため、そうではありません。)

于 2012-06-16T00:24:14.433 に答える
0

main 関数を使用しているプロジェクトで、すべての依存 dll (アクティビティとワークフローの開発に使用されるもの) を参照します。

于 2012-06-21T12:02:15.010 に答える