IfElseActivity
1.IfElseActivity有两个IfElseBranch子控件,分别作为IfElse的两个分支容器,系统自动添加,
2.其中左边(为真件条)的IfElseBranch容器要设Condition
3.IfElse左边(为真件条)的IfElseBranch容器的Condition有两个条件模式:Code Condition,Declarative Rule Condition
Code Condition模式
Code Condition模式,由对e.Result赋不同值决定执行不同的分支
要使用该模式,会在代码中用到CodeCondition对象与CodeCondition对象的Condition事件Private Sub ifElse_a_Condition()Sub ifElse_a_Condition(ByVal sender As System.Object, ByVal e As System.Workflow.Activities.ConditionalEventArgs)
'e.Result如果为真,就执行左边(为真件条)的IfElseBranch容器
'e.Result如果为假,就执行右边(为假件条)的IfElseBranch容器
If temp = "456" Then
e.Result = True
Else
e.Result = False
End If
End Sub
双击无法进入代码,可手写该过程,
从下拉框绑定时如报错,可在Workflow1.designer.vb中的手写绑定代码Dim codecondition1 As System.Workflow.Activities.CodeCondition = New System.Workflow.Activities.CodeCondition
AddHandler codecondition1.Condition, AddressOf Me.ifElse_a_Condition
Me.ifElseBranchActivity1.Condition = codecondition1
Declarative Rule Condition模式
Declarative Rule Condition模式:由指定的表达式的值是否符合条件定执行不同的分支
代码实现
Workflow1.rules |
<RuleDefinitions xmlns="http://schemas.microsoft.com/winfx/2006/xaml/workflow"> <RuleDefinitions.Conditions> <RuleExpressionCondition Name="Condition1"> <RuleExpressionCondition.Expression> <ns0:CodeBinaryOperatorExpression Operator="ValueEquality" xmlns:ns0="clr-namespace:System.CodeDom;Assembly=System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <ns0:CodeBinaryOperatorExpression.Left> <ns0:CodeFieldReferenceExpression FieldName="temp"> <ns0:CodeFieldReferenceExpression.TargetObject> <ns0:CodeThisReferenceExpression /> </ns0:CodeFieldReferenceExpression.TargetObject> </ns0:CodeFieldReferenceExpression> </ns0:CodeBinaryOperatorExpression.Left> <ns0:CodeBinaryOperatorExpression.Right> <ns0:CodePrimitiveExpression> <ns0:CodePrimitiveExpression.Value> <ns1:String xmlns:ns1="clr-namespace:System;Assembly=mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">123</ns1:String> </ns0:CodePrimitiveExpression.Value> </ns0:CodePrimitiveExpression> </ns0:CodeBinaryOperatorExpression.Right> </ns0:CodeBinaryOperatorExpression> </RuleExpressionCondition.Expression> </RuleExpressionCondition> </RuleDefinitions.Conditions> </RuleDefinitions> |
Dim ruleconditionreference1 As Workflow.Activities.Rules.RuleConditionReference = New .RuleConditionReference ruleconditionreference1.ConditionName = "Condition1" Me.ifElseBranchActivity3.Condition = ruleconditionreference1 |