本節主要介紹如何在WF4.0中使用變量,以及為變量賦值
本文例子下載:
http://files.cnblogs.com/foundation/VariablesSample.rar
http://files.cnblogs.com/foundation/AssignSample.rar
數據的傳遞 Variable變量
Variable變量
System.Activities.Variable 類
類名 System.Activities.Statements. 文件 System.Activities.dll 結構說明 繼承 System.Activities.LocationReference變量說明
1.只有具備[Variables]屬性的Activity才可以定義變量
2.[Variables] 的數據類型為System.Collections.ObjectModel.Collection<System.Activities.Variable>
3.在定義變量的[Activity]內部的[Activity]可以訪問變量,在定義變量的[Activity]外部的[Activity]無法訪問變量
其XAML結構如下
<Activity ... >
<Sequence DisplayName="mySequenceA" ... >
<Sequence.Variables>
<Variable x:TypeArguments="x:String" Name="v1" />
<Variable x:TypeArguments="x:String" Name="v2" />
</Sequence.Variables>
<sap:WorkflowViewStateService.ViewState>
<scg3:Dictionary x:TypeArguments="x:String, x:Object">
<x:Boolean x:Key="IsExpanded">True</x:Boolean>
</scg3:Dictionary>
</sap:WorkflowViewStateService.ViewState>
<Sequence DisplayName="mySequenceB" sap:VirtualizedContainerService.HintSize="200,100">
<Sequence.Variables>
<Variable x:TypeArguments="x:String" Name="v3" />
<Variable x:TypeArguments="x:String" Name="v4" />
</Sequence.Variables>
<sap:WorkflowViewStateService.ViewState>
<scg3:Dictionary x:TypeArguments="x:String, x:Object">
<x:Boolean x:Key="IsExpanded">True</x:Boolean>
<x:Boolean x:Key="IsPinned">False</x:Boolean>
</scg3:Dictionary>
</sap:WorkflowViewStateService.ViewState>
</Sequence>
</Sequence>
</Activity>
為具備[Variables]屬性的Activity添加變量
使用變量
可在Activity的表達式類型屬性裡直接賦予變量名
運行結果
Assign 賦值
類名 System.Activities.Statements.Assign 文件 System.Activities.dll 結構說明 繼承 CodeActivity
例子:
1.在Sequence容器中定義一個變量[v1],類型為"String",默認值為"wxwinter"
2.用WriteLine在屏幕上輸出變量[v1]的值
3.用[Assign]將變量[v1]賦值為"wxd"
4.用WriteLine在屏幕上輸出變量[v1]的值
5.用[Assign]將變量[v1]賦值為"lzm"
6.用WriteLine在屏幕上輸出變量[v1]的值
運行結果