[WF4]My Composite Activity

Activity Designer:

<sap:ActivityDesigner x:Class="MyActivityLibrary.MyCompositeDesigner"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:sap="clr-namespace:System.Activities.Presentation;assembly=System.Activities.Presentation"

    xmlns:sapv="clr-namespace:System.Activities.Presentation.View;assembly=System.Activities.Presentation">

    <Grid>

        <StackPanel>

            <sap:WorkflowItemsPresenter HintText="Drop Activities Here"

                                        Items="{Binding Path=ModelItem.Branches,Mode=TwoWay}">

                <sap:WorkflowItemsPresenter.SpacerTemplate>

                    <DataTemplate>

                        <Path Margin="0,15,0,0"                                             

                              Stretch="Fill"

                                    StrokeMiterLimit="2.75"

                                    Stroke="#FFA8B3C2" Fill="#FFFFFFFF"

                                    Data="F1 M 675.738,744.979L 665.7,758.492L 655.66,744.979L 675.738,744.979 Z "

                                    Width="16" Height="10" />

                    </DataTemplate>

                </sap:WorkflowItemsPresenter.SpacerTemplate>

                <sap:WorkflowItemsPresenter.ItemsPanel>

                    <ItemsPanelTemplate>

                        <StackPanel Orientation="Vertical"/>

                    </ItemsPanelTemplate>

                </sap:WorkflowItemsPresenter.ItemsPanel>

            </sap:WorkflowItemsPresenter>

        </StackPanel>

    </Grid>

</sap:ActivityDesigner>

 

 Activity code

    [Designer(typeof(MyCompositeDesigner))]

    public class MyCompositeActivity:NativeActivity {

        public Collection<Activity> Branches { get; set; }

        public Collection<Variable> Variables { get; set; }

        public MyCompositeActivity() {

            Branches = new Collection<Activity>();

            Variables= new Collection<Variable>();

        }

 

        int activityCounter = 0;

        protected override void CacheMetadata(NativeActivityMetadata metadata) {

            metadata.SetChildrenCollection(Branches);

            metadata.SetVariablesCollection(Variables);

        }

        protected override void Execute(NativeActivityContext context) {

            ScheduleActivities(context);

        }

        void ScheduleActivities(NativeActivityContext context) {

            if(activityCounter<Branches.Count)

                context.ScheduleActivity(this.Branches[activityCounter++],OnActivityCompleted);

        }

        void OnActivityCompleted(NativeActivityContext context, ActivityInstance completedInstance) {

            ScheduleActivities(context);

        }

    }

Final View

blog comments powered by Disqus