自定义的Activity。
[Designer(typeof(CompositeDesigner))] public class SingleActivity : NativeActivity { private Activity doWhileActivity; public Activity DoWhileActivity { get { return this.doWhileActivity; } set { this.doWhileActivity = value; } } public SingleActivity() { doWhileActivity = CreateDoWhile(); } protected override void CacheMetadata(NativeActivityMetadata metadata) { metadata.AddChild(DoWhileActivity); base.CacheMetadata(metadata); } protected override void Execute(NativeActivityContext context) { context.ScheduleActivity(this.DoWhileActivity, onActivityCompleted); } void onActivityCompleted(NativeActivityContext context, ActivityInstance instance) { } private Activity CreateDoWhile() { Variable<bool> VResult = new Variable<bool>("VResult", false); return new DoWhile() { DisplayName = "DoWhile", Variables = { VResult }, Condition = ExpressionServices.Convert<bool>(env => !VResult.Get(env)), Body = new Sequence() { DisplayName = "DoWhile Body", Activities = { new TestActivity(){ MyOut=VResult}, new If() { DisplayName = "If Then Else", //Code to be added here in Level 2 Condition = ExpressionServices.Convert<bool>(env => VResult.Get(env)), Then = new IFThenActivity() { DisplayName="Set Resut True", InOutResult=VResult}, Else = new IFElseActivity(){ DisplayName="Double Click End Key"} } } } }; } }
Designer
<sap:ActivityDesigner.Resources> <DataTemplate x:Key="Collapsed"> <StackPanel> <TextBlock FontStyle="Oblique" Foreground="Gray">请双击查看</TextBlock> </StackPanel> </DataTemplate> <DataTemplate x:Key="Expanded"> <StackPanel> <Border BorderBrush="Green" BorderThickness="4" CornerRadius="2" Margin="3"> <StackPanel> <TextBlock HorizontalAlignment="Center" FontWeight="Bold">DoWhile Activity</TextBlock> <sap:WorkflowItemPresenter Margin="3" Item="{Binding Path=ModelItem.DoWhileActivity, Mode=TwoWay}" HintText="请拖拽活动到这里"/> </StackPanel> </Border> </StackPanel> </DataTemplate> <Style x:Key="ExpandOrCollapsedStyle" TargetType="{x:Type ContentPresenter}"> <Setter Property="ContentTemplate" Value="{DynamicResource Expanded}"/> <Style.Triggers> <DataTrigger Binding="{Binding Path=ShowExpanded}" Value="false"> <Setter Property="ContentTemplate" Value="{DynamicResource Collapsed}"/> </DataTrigger> </Style.Triggers> </Style> </sap:ActivityDesigner.Resources> <Grid> <ContentPresenter Style="{DynamicResource ExpandOrCollapsedStyle}" Content="{Binding}" /> </Grid>
当Activiy拖拽到工作流中时,如何不让用户Delete 自定义活动中的属性DoWhileActivity.
也不能在DoWhile的
Body = new Sequence()
里面添加其他Activiy。