Property Promotion in WF

When building Sequential Activities in Workflow (WF) (see Figure 1) there will come a time when you add child activities of your own to the Sequential Activity. When you do this you will quickly see that the designer does not give you access to your child activity properties (see Figure 2). The entries are in the property window but they are grayed out. So what do you do to solve this? Well you use Property Promotion to promote the properties visibility to the parent activity. To do this go to the child activity and select the property you created (see listing 1) in the properties window when you are in design mode. Then select from the drop down (see Figure 3) and then enter the value for the binding in the parent activity (see Figure 4). This will add a DependencyProperty property to the Parent Activity (see listing 2) so the property is now available in the parent activity. You can see in the code that the dependency property is referencing the child property using the name you entered in the binding dialog (see Figure 4) earlier.

WorkflowSequentialExample

Figure 1 (sample workflow)

Disabled Child Properties

Figure 2 (Disabled Property)

       public static DependencyProperty EchoTextProperty = System.Workflow.ComponentModel.DependencyProperty.Register(“EchoText”, typeof(string), typeof(ActivityEcho));

        [Description(“Text to echo”)]
        [Category(“Input Data”)]
        [Browsable(true)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        public string EchoText
        {
            get
            {
                return ((string)(base.GetValue(ActivityEcho.EchoTextProperty)));
            }
            set
            {
                base.SetValue(ActivityEcho.EchoTextProperty, value);
            }
        }

Listing 1 (Dependency Property of the Child Activity)

ChildActivityPromote

Figure 3 (Promote)

PromoteBinding

Figure 4 (promote binding)

        public static DependencyProperty activityEcho1_EchoText2Property = DependencyProperty.Register(“activityEcho1_EchoText2”, typeof(System.String), typeof(Echo.ActivityComposite));

        [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
        [ValidationOptionAttribute(ValidationOption.Optional)]
        [BrowsableAttribute(true)]
        [CategoryAttribute(“Input Data”)]
        public String activityEcho1_EchoText2
        {
            get
            {
                return ((string)(base.GetValue(Echo.ActivityComposite.activityEcho1_EchoText2Property)));
            }
            set
            {
                base.SetValue(Echo.ActivityComposite.activityEcho1_EchoText2Property, value);
            }
        }

Listing 2 (Parent Actiivty’s new DependencyProperty entry)

Leave a Reply

Your email address will not be published. Required fields are marked *