raj raj

raj raj

  • 1.1k
  • 256
  • 18.3k

How to create own foreach activity workflow in c#

May 21 2023 12:45 PM

We have inbuilt foreachwithbodyfactory activity which we need to pass datatablename.Asenumarable but in our requirement 
we do not want to pass this asenumarable with datatablename.
we are creating our own custom foreachwithbodyfactory activity.
we have created someting but fully it is not working.
below is our activity class and designer page.

activity.cs

[Designer(typeof(mydesignerpage)), ContentProperty("Child")]
public sealed class MyActivity :  NativeActivity, IActivityTemplateFactory
{   
    public ActivityAction Child { get; set; }   
    protected override void  CacheMetadata(NativeActivityMetadata metadata)
    {
        metadata.AddDelegate(Child);
    }
    protected override void  Execute(NativeActivityContext context)
    {        
        context.ScheduleAction(Child);
    }    
    Activity IActivityTemplateFactory.Create(System.Windows.DependencyObject target)
    {
        return new MyActivity
        {
            
            Child = new ActivityAction()
        };
    }
}


mydesignerpage

<ActivityDesigner x:Class="Excel.Design.ForEachDataTableView"
             
             xmlns:sap="clr-namespace:System.Activities.Presentation;assembly=System.Activities.Presentation"
    xmlns:sapv="clr-namespace:System.Activities.Presentation.View;assembly=System.Activities.Presentation" Height="500" Width="400">


    <Grid Width="400" Height="200">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="223*"/>
            <ColumnDefinition Width="177*"/>
        </Grid.ColumnDefinitions>
        <Label Content="ForEach" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="22,10,0,0"/>
        <TextBox HorizontalAlignment="Left" Height="26" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="60" Margin="79,10,0,0"/>
        <Label Content="in" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="195,10,0,0"/>
        <TextBox HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="120" Margin="9.588,13,0,0" Grid.Column="1"/>
        <sap:WorkflowItemPresenter     HintText="Drop activity here!"     Item="{Binding Path=ModelItem.Child.Handler}" RenderTransformOrigin="0.5,0.5" Grid.ColumnSpan="2" >

        </sap:WorkflowItemPresenter>    

    </Grid>
</ActivityDesigner>

 


Answers (4)