none
How to define a custom activity that can be the scope of a variable? RRS feed

  • Question

  • When I rehost a designer, I can declare variables and their scopes. However, not all activities can be the scope of a variable. I notice Sequence, Parallel, PickBranch can be the host, but Pick, If, Delay, can't. And all of my custom activities currently cannot be the scope of a variable. What should I do to make a custom activity able to be the scope of variables?
    • Changed type Louis Rhys Friday, January 21, 2011 7:38 AM
    Friday, January 21, 2011 3:37 AM

Answers

  • Hi Louis,

    If you want to use Variables Designer to add/delete/update the variables on your custom activity, I think you can just declare a property named 'Variables' of type Collection<Variable>.  And create an instance of the variable collection in your activities constructor. Then when you drag this activities to designer surface, then you will see the Variables Designer will allow to add variables to this custom activity. Here is a very simply code:

      public class MyActivity : NativeActivity
      {
        public Collection<Variable> Variables { get; set; }
        public Activity Body { get; set; }
    
        public MyActivity()
        {
          //Initialize the collection here.
          Variables = new Collection<Variable>();
    
        }...
    

    This posting is provided "AS IS" and confers no rights or warranties.
    • Marked as answer by Louis Rhys Friday, January 21, 2011 4:17 PM
    • Unmarked as answer by Louis Rhys Monday, January 24, 2011 2:55 AM
    • Marked as answer by Louis Rhys Monday, January 24, 2011 3:05 AM
    Friday, January 21, 2011 10:05 AM
    Moderator

All replies

  • Hi Louis,

    If you want to use Variables Designer to add/delete/update the variables on your custom activity, I think you can just declare a property named 'Variables' of type Collection<Variable>.  And create an instance of the variable collection in your activities constructor. Then when you drag this activities to designer surface, then you will see the Variables Designer will allow to add variables to this custom activity. Here is a very simply code:

      public class MyActivity : NativeActivity
      {
        public Collection<Variable> Variables { get; set; }
        public Activity Body { get; set; }
    
        public MyActivity()
        {
          //Initialize the collection here.
          Variables = new Collection<Variable>();
    
        }...
    

    This posting is provided "AS IS" and confers no rights or warranties.
    • Marked as answer by Louis Rhys Friday, January 21, 2011 4:17 PM
    • Unmarked as answer by Louis Rhys Monday, January 24, 2011 2:55 AM
    • Marked as answer by Louis Rhys Monday, January 24, 2011 3:05 AM
    Friday, January 21, 2011 10:05 AM
    Moderator
  • Cool. Thanks!
    Monday, January 24, 2011 3:05 AM