C# 这两个XAML在工作流基础上的区别是什么? 遇到了Windows工作流基础中指定的两种XAML,我只想知道它们之间的差异。

C# 这两个XAML在工作流基础上的区别是什么? 遇到了Windows工作流基础中指定的两种XAML,我只想知道它们之间的差异。,c#,xaml,workflow,workflow-foundation-4,workflow-foundation,C#,Xaml,Workflow,Workflow Foundation 4,Workflow Foundation,类型1 <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (c) Microsoft Corporation. All rights reserved. --> <Activity mc:Ignorable="sap" x:Class="Microsoft.Samples.InvokeMethodUsage.Sequence1" mva:VisualBasic.Settings="Assembly refer

类型1

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) Microsoft Corporation. All rights reserved. -->
<Activity mc:Ignorable="sap" x:Class="Microsoft.Samples.InvokeMethodUsage.Sequence1" mva:VisualBasic.Settings="Assembly references and imported namespaces serialized as XML namespaces" xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:msi="clr-namespace:Microsoft.Samples.InvokeMethodUsage;assembly=InvokeMethodUsage" xmlns:msi1="clr-namespace:Microsoft.Samples.InvokeMethodUsage;assembly=InvokeMethodUsage, Version=1.0.3516.24075, Culture=neutral, PublicKeyToken=null" 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:sa="clr-namespace:System.Activities;assembly=System.Activities" 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=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Sequence sap:VirtualizedContainerService.HintSize="333.663333333333,3387.23666666666">
    <Sequence.Variables>
        <Variable x:TypeArguments="x:String" Default="[&quot;this is an out param&quot;]" Name="outParam" />
        <Variable x:TypeArguments="x:Int32" Name="resultValue" />
        <Variable x:TypeArguments="msi:TestClass" Default="[New TestClass()]" Name="varTestClass" />
    </Sequence.Variables>
    <sap:WorkflowViewStateService.ViewState>
  <scg:Dictionary x:TypeArguments="x:String, s:Object">
    <x:Boolean x:Key="IsExpanded">True</x:Boolean>
  </scg:Dictionary>
</sap:WorkflowViewStateService.ViewState>
    <WriteLine sap:VirtualizedContainerService.HintSize="299.663333333333,59.2766666666667" Text="[&quot;Instance method call&quot;]" />


    <InvokeMethod DisplayName="Instance Method Call" sap:VirtualizedContainerService.HintSize="299.663333333333,127.553333333333" MethodName="InstanceMethod1">
        <InvokeMethod.TargetObject>
            <InArgument x:TypeArguments="msi:TestClass">[New TestClass()]</InArgument>
        </InvokeMethod.TargetObject>
    </InvokeMethod>


    <WriteLine sap:VirtualizedContainerService.HintSize="299.663333333333,59.2766666666667" Text="[&quot;Instance Method Call with Parameters&quot;]" />
<InvokeMethod DisplayName="Instance Method Call with Parameters" sap:VirtualizedContainerService.HintSize="299.663333333333,127.553333333333" MethodName="InstanceMethod">
  <InvokeMethod.TargetObject>
    <InArgument x:TypeArguments="msi:TestClass">[New TestClass()]</InArgument>
  </InvokeMethod.TargetObject>
  <InArgument x:TypeArguments="x:String">["My favorite number is"]</InArgument>
  <InArgument x:TypeArguments="x:Int32">42</InArgument>
</InvokeMethod>
<WriteLine sap:VirtualizedContainerService.HintSize="299.663333333333,59.2766666666667" Text="[&quot;Instance Method Call with Parameter Arrays&quot;]" />
<InvokeMethod DisplayName="Instance Method Call with Parameter Arrays" sap:VirtualizedContainerService.HintSize="299.663333333333,127.553333333333" MethodName="InstanceMethod">
  <InvokeMethod.TargetObject>
    <InArgument x:TypeArguments="msi:TestClass">[New TestClass()]</InArgument>
  </InvokeMethod.TargetObject>
  <InArgument x:TypeArguments="x:String">["My favorite number is"]</InArgument>
  <InArgument x:TypeArguments="x:Int32">42</InArgument>
  <InArgument x:TypeArguments="x:String">["first item of the param array"]</InArgument>
  <InArgument x:TypeArguments="x:String">["second item of the param array"]</InArgument>
  <InArgument x:TypeArguments="x:String">["third item of the param array"]</InArgument>
</InvokeMethod>
<WriteLine sap:VirtualizedContainerService.HintSize="299.663333333333,59.2766666666667" Text="[&quot;Instance Method Call with Parameters and Return Value&quot;]" />
<InvokeMethod DisplayName="Instance Method Call with Parameters and Return Value" sap:VirtualizedContainerService.HintSize="299.663333333333,127.553333333333" MethodName="InstanceMethodWithResult">
  <InvokeMethod.Result>
    <OutArgument x:TypeArguments="x:Int32">[resultValue]</OutArgument>
  </InvokeMethod.Result>
  <InvokeMethod.TargetObject>
    <InArgument x:TypeArguments="msi:TestClass">[New TestClass()]</InArgument>
  </InvokeMethod.TargetObject>
  <InArgument x:TypeArguments="x:Int32">20</InArgument>
  <InArgument x:TypeArguments="x:Int32">22</InArgument>
</InvokeMethod>
<WriteLine sap:VirtualizedContainerService.HintSize="299.663333333333,59.2766666666667" Text="[String.Format(&quot;....Result: {0}&quot;, resultValue)]" />
<WriteLine sap:VirtualizedContainerService.HintSize="299.663333333333,59.2766666666667" Text="[&quot;Static Method Call with Parameters&quot;]" />
<InvokeMethod DisplayName="Static Method Call with Parameters" sap:VirtualizedContainerService.HintSize="299.663333333333,127.553333333333" MethodName="StaticMethod" TargetType="msi:TestClass">
  <InArgument x:TypeArguments="x:String">["My favorite number is"]</InArgument>
  <InArgument x:TypeArguments="x:Int32">42</InArgument>
</InvokeMethod>
<WriteLine sap:VirtualizedContainerService.HintSize="299.663333333333,59.2766666666667" Text="[&quot;Generic Instance Method Call with Generic Parameters&quot;]" />
<InvokeMethod DisplayName="Generic Instance Method Call with Generic Parameters" sap:VirtualizedContainerService.HintSize="299.663333333333,127.553333333333" MethodName="GenericInstanceMethod">
  <InvokeMethod.GenericTypeArguments>
    <x:Type Type="x:String" />
  </InvokeMethod.GenericTypeArguments>
  <InvokeMethod.TargetObject>
    <InArgument x:TypeArguments="msi:TestClass">[New TestClass()]</InArgument>
  </InvokeMethod.TargetObject>
  <InArgument x:TypeArguments="x:String">["Hello world"]</InArgument>
</InvokeMethod>
<WriteLine sap:VirtualizedContainerService.HintSize="299.663333333333,59.2766666666667" Text="[&quot;Generic Static Method Call with Two Generic Parameters&quot;]" />
<InvokeMethod DisplayName="Generic Static Method Call with Two Generic Parameters" sap:VirtualizedContainerService.HintSize="299.663333333333,127.553333333333" MethodName="GenericStaticMethod" TargetType="msi:TestClass">
  <InvokeMethod.GenericTypeArguments>
    <x:Type Type="x:String" />
    <x:Type Type="x:Int32" />
  </InvokeMethod.GenericTypeArguments>
  <InArgument x:TypeArguments="x:String">["Favorite number"]</InArgument>
  <InArgument x:TypeArguments="x:Int32">42</InArgument>
</InvokeMethod>
<WriteLine sap:VirtualizedContainerService.HintSize="299.663333333333,59.2766666666667" Text="[&quot;Instance Method Call with Parameters by Reference&quot;]" />
<InvokeMethod DisplayName="Instance Method Call with Parameters by Rerefence" sap:VirtualizedContainerService.HintSize="299.663333333333,127.553333333333" MethodName="InstanceMethod">
  <InvokeMethod.TargetObject>
    <InArgument x:TypeArguments="msi:TestClass">[New TestClass()]</InArgument>
  </InvokeMethod.TargetObject>
  <InArgument x:TypeArguments="x:String">["My favorite number is"]</InArgument>
  <InArgument x:TypeArguments="x:Int32">42</InArgument>
  <InOutArgument x:TypeArguments="x:String">[outParam]</InOutArgument>
</InvokeMethod>
<WriteLine sap:VirtualizedContainerService.HintSize="299.663333333333,59.2766666666667" Text="[String.Format(&quot;....out param changed to: {0}&quot;, outParam)]" />
<WriteLine sap:VirtualizedContainerService.HintSize="299.663333333333,59.2766666666667" Text="[&quot;Async Instance Method Call&quot;]" />
<InvokeMethod DisplayName="Async Instance Method Call" sap:VirtualizedContainerService.HintSize="299.663333333333,127.553333333333" MethodName="AsyncMethodSample" RunAsynchronously="True">
  <InvokeMethod.TargetObject>
    <InArgument x:TypeArguments="msi:TestClass">[New TestClass()]</InArgument>
  </InvokeMethod.TargetObject>
  <InArgument x:TypeArguments="x:String">["Hello async"]</InArgument>
</InvokeMethod>
<WriteLine sap:VirtualizedContainerService.HintSize="299.663333333333,59.2766666666667" Text="[&quot;Store a Value&quot;]" />
<InvokeMethod DisplayName="Store a Value in an Instance" sap:VirtualizedContainerService.HintSize="299.663333333333,127.553333333333" MethodName="StoreValue">
  <InvokeMethod.TargetObject>
    <InArgument x:TypeArguments="msi:TestClass">[varTestClass]</InArgument>
  </InvokeMethod.TargetObject>
  <InArgument x:TypeArguments="x:Int32">42</InArgument>
</InvokeMethod>
<WriteLine sap:VirtualizedContainerService.HintSize="299.663333333333,59.2766666666667" Text="[&quot;Get a Value&quot;]" />
<InvokeMethod DisplayName="Get a Value from an Instance" sap:VirtualizedContainerService.HintSize="299.663333333333,127.553333333333" MethodName="GetValue">
  <InvokeMethod.Result>
    <OutArgument x:TypeArguments="x:Int32">[resultValue]</OutArgument>
  </InvokeMethod.Result>
  <InvokeMethod.TargetObject>
    <InArgument x:TypeArguments="msi:TestClass">[varTestClass]</InArgument>
  </InvokeMethod.TargetObject>
</InvokeMethod>
<InvokeMethod DisplayName="Write a Blank Line to the Console" sap:VirtualizedContainerService.HintSize="299.663333333333,127.553333333333" MethodName="WriteLine" TargetType="s:Console">
  <InArgument x:TypeArguments="x:String">[String.Format("....the stored value is {0}", resultValue)]</InArgument>
</InvokeMethod> 
</Sequence>

真的
[新TestClass()]
[新TestClass()]
[“我最喜欢的号码是”]
42
[新TestClass()]
[“我最喜欢的号码是”]
42
[“参数数组的第一项”]
[“参数数组的第二项”]
[“参数数组的第三项”]
[结果值]
[新TestClass()]
20
22
[“我最喜欢的号码是”]
42
[新TestClass()]
[“你好,世界”]
[“最喜欢的号码”]
42
[新TestClass()]
[“我最喜欢的号码是”]
42
[输出参数]
[新TestClass()]
[“Hello async”]
[varTestClass]
42
[结果值]
[varTestClass]
[String.Format(“……存储值为{0}”,resultValue)]

类型2

<SequentialWorkflowActivity x:Class="myxmsapplication.Workflow2" x:Name="Workflow2" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/workflow">|
   <WhileActivity x:Name="whileActivity1">
          <WhileActivity.Condition>
                 <RuleConditionReference ConditionName="Condition1" />
          </WhileActivity.Condition>
          <IfElseActivity x:Name="ifElseActivity1">
                 <IfElseBranchActivity x:Name="ifElseBranchActivity1">
                       <IfElseBranchActivity.Condition>
                              <RuleConditionReference ConditionName="Condition2" />
                       </IfElseBranchActivity.Condition>
                       <CodeActivity x:Name="codeActivity1" ExecuteCode="codeActivity1_ExecuteCode" />
                 </IfElseBranchActivity>
                 <IfElseBranchActivity x:Name="ifElseBranchActivity2">
                       <IfElseBranchActivity.Condition>
                              <RuleConditionReference ConditionName="Condition3" />
                       </IfElseBranchActivity.Condition>
                       <CodeActivity x:Name="codeActivity2" ExecuteCode="codeActivity2_ExecuteCode" />
                 </IfElseBranchActivity>
          </IfElseActivity>
   </WhileActivity>
|

观察

这与XAML中的数据无关,而是与结构有关。
前一个根标记是Activity,其子标记是Sequence,而后者以宽名称SequenceWorkflowActivity开头。在工作流基础中,有人能解释这些差异吗?

< P> 1类型的XAML是Windows工作流基础的4。x版本,而类型2的示例是3。x版本。

可以在程序中以4×x生成XAML吗?是的,这是绝对可能的。您需要使用ActivityBuilder和XamlActivityServices类型来读写Xaml。谢谢。你可以发布一些关于4.xWF的状态机工作流XAML示例的链接吗。