首页 新闻 会员 周边 捐助

自定义的Activity,如何禁止修改,并且还能呈现在Designer上?

0
[已关闭问题] 关闭于 2014-12-04 16:02

自定义的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。

亲福的主页 亲福 | 初学一级 | 园豆:40
提问于:2013-09-17 13:09
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册