locked
Custom Activity having another activity RRS feed

  • Question

  • Hi,

    I need to develop a custom activity which contain a FlowChart activity as an inbuilt one. Basically the requirement is to have FlowChart activity as the ROOT activity when the user wanted to create a new WF in the WPF rehosted designer. . . something similar to Sequence activity that is comming as default ROOT activity........ I did achieved this and the following is the sample code.....

    namespace CustomActivities
    {
        [Designer(typeof(CustomActivities.CustActivityDesigner))]
        public sealed class CustActivity : NativeActivity
        {
            [Browsable(false)]
            public Collection<Activity> Activities { get; set; }
        
            public CustActivity()
            {
                Activities = new Collection<Activity>();
                System.Activities.Statements.Flowchart fl = new System.Activities.Statements.Flowchart();

                Activities.Add(fl);
            }
     
            protected override void CacheMetadata(NativeActivityMetadata metadata)
            {
                metadata.SetChildrenCollection(Activities);
            }
     
            protected override void Execute(NativeActivityContext context)
            {
                
            }
        }
    }

     Here the problem is, whenever the workflow is saved and reopened in the WF designer, the FlowChart activity is getting duplicated . . .. because the constructor creates a new FlowChart . .. I don't want this duplicate. How to achieve this ?

    Wednesday, November 10, 2010 8:33 AM

Answers

  • I don't understand why you have to add the flowchart activity into your custom activity ctor.

    can you consider this solution?

    keep your custom activity alone, and remove add flowchart step.

    and then create following custom activity

    and add this activity to the designer surface. this can meet your request.

     

    public sealed class myActivityA : System.Activities.Presentation.IActivityTemplateFactory

    {

     

    public Activity Create(DependencyObject target)

    {

    CustomActivity activity = new CustomActivity();
    activity.Activities.Add(new Flowchart());
     

    return activity;

    }

    }

    • Marked as answer by prabashmi Friday, November 12, 2010 6:59 AM
    Friday, November 12, 2010 2:03 AM

All replies

  • Hi

    Basically what you can do here is directly load the FlowChart activity into your re-hosted application, then you can get FlowChart as the ROOT activity inside the workflow. See the below code snippet

     

    private WorkflowDesigner wd;

    ...

    this.wd = new WorkflowDesigner();
    this.wd.Load(new FlowChart());

     

     

    jhlim

    Wednesday, November 10, 2010 9:57 AM
  • Hi,

    This sample could be helpful to you:
    http://xhinker.com/post/WF4Custom-WF4-Designer.aspx

    Regards
    This posting is provided "AS IS" with no warranties, and confers no rights. Microsoft Online Community Support. My Blog:http://xhinker.com "Microsoft Windows Workflow Foundation 4.0 Cookbook"
    Thursday, November 11, 2010 8:51 AM
  • This I know and have tried it already. But my problem is . .. .  i have to have a custom activity (composing multiple activities) and this will have a FlowChart activity as first one and since the FlowChart activity is created in the CONSTRUCTOR of a custom activity, it is getting added (duplicated) everytime when i reopen the XAMLX.

     

    Thursday, November 11, 2010 10:18 AM
  • I don't understand why you have to add the flowchart activity into your custom activity ctor.

    can you consider this solution?

    keep your custom activity alone, and remove add flowchart step.

    and then create following custom activity

    and add this activity to the designer surface. this can meet your request.

     

    public sealed class myActivityA : System.Activities.Presentation.IActivityTemplateFactory

    {

     

    public Activity Create(DependencyObject target)

    {

    CustomActivity activity = new CustomActivity();
    activity.Activities.Add(new Flowchart());
     

    return activity;

    }

    }

    • Marked as answer by prabashmi Friday, November 12, 2010 6:59 AM
    Friday, November 12, 2010 2:03 AM
  • wow . ..  its cool !

    Thanks Ye Yu . ..  It works good.

    Now, i wanted to make the flowchart as non-deletable one. Through the WF designer, user should not be able to delete the flowchart that is part of my custom activity.

    Please suggest a way.

    Friday, November 12, 2010 6:59 AM
  • you may refer to this post

    http://social.msdn.microsoft.com/Forums/zh-CN/wfprerelease/thread/26556475-93ff-4954-9635-471ba34a687e

     

    it's the same question as yours, and there is sample code post there.

    Friday, November 12, 2010 7:35 AM
  • are you asking disable delete command or suppress validation?

    I'm confused

    Monday, November 15, 2010 2:07 AM
  • oh I'm sorry, its my confusion, this supposed to be placed in a different thread, accidently pasted here. . . .sorry about the confusion.

    Monday, November 15, 2010 9:20 AM
  • Thanks, It helps me to disable DELETE . ..  now the user is not able to delete activity using DELETE key using keyboard or using right-click context menu.

    The same way when I implement it for CUT, it disables for pressing CTRL+X ..  . but not disabling the right-click context menu on a given activity . . ..  Please suggest a way to disable CUT

    Here is the sample code that i have tried . . . . .

    <sap:ActivityDesigner.CommandBindings>
        <CommandBinding Command = "Cut" CanExecute = "CutCommand_CanExecute"/>
        <CommandBinding Command = "Delete" CanExecute = "DeleteCommand_CanExecute"/>
      </sap:ActivityDesigner.CommandBindings>
    
    private void DeleteCommand_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
          //MessageBox.Show("Can Execute Delete ..... ");
          e.ContinueRouting = false;
          e.CanExecute = false;
          e.Handled = true;
        }
        private void CutCommand_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
          //MessageBox.Show("Cut Can Execute . . . .. ");
          e.ContinueRouting = false;
          e.CanExecute = false;
          e.Handled = true;
        }
    
    Tuesday, November 16, 2010 1:56 PM