locked
How to set bindings for generic properties of custom activity in workflow foundation

    Question

  • Hi folks,

    I have a custom class called "Parameter" and a custom activity with generic collection property called "Parameters", and I want to set bindings for one of Parameters in the generic list of Parameters Property,I've tried with activitybind, but it is not working, is there any way to do it with workflow foundation? please see codes below:

    public class Parameter:DependencyObject //A Class
    {
    public string Name
    {
        get { return (string)GetValue(NameProperty); }
        set { SetValue(NameProperty, value); }
    }
    
    // Using a DependencyProperty as the backing store for Name.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty NameProperty =
        DependencyProperty.Register("Name", typeof(string), typeof(Parameter));
    
    public string Value
    {
        get { return (string)GetValue(ValueProperty); }
        set { SetValue(ValueProperty, value); }
    }
    
    // Using a DependencyProperty as the backing store for Value.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty ValueProperty =
        DependencyProperty.Register("Value", typeof(string), typeof(Parameter));
    }
    
    A Custom Activity with generic property

      public partial class Activity1 : System.Workflow.ComponentModel.Activity
    {
            public Activity1()
            {
                    InitializeComponent();
            }
    
    protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
    {
        return base.Execute(executionContext);
    }
    
    public List<Parameter> Parameters
    {
        get { return (List<Parameter>)GetValue(ParametersProperty); }
        set { SetValue(ParametersProperty, value); }
    }
    
    // Using a DependencyProperty as the backing store for Parameters.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty ParametersProperty =
        DependencyProperty.Register("Parameters", typeof(List<Parameter>), typeof(Activity1));
    
    Designer Code

       #region Designer generated code
    
        /// <summary> 
        /// Required method for Designer support - do not modify 
        /// the contents of this method with the code editor.
        /// </summary>
        [System.Diagnostics.DebuggerNonUserCode]
        private void InitializeComponent()
        {
            this.CanModifyActivities = true;
            this.activity12 = new ActivityLibrary1.Activity1();
            this.activity11 = new ActivityLibrary1.Activity1();
    
            List<Parameter> paras1 = new List<Parameter>();
            paras1.Add(new Parameter() { Name = "a", Value = "a" });
            paras1.Add(new Parameter() { Name = "b", Value = "b" });
    
            List<Parameter> paras2 = new List<Parameter>();
            paras2.Add(new Parameter() { Name = "c", Value = "c" });
            paras2.Add(new Parameter() { Name = "d", Value = "d" });
            // 
            // activity12
            // 
            this.activity12.Name = "activity12";
            this.activity12.Parameters = paras1;
            // 
            // activity11
            // 
            this.activity11.Name = "activity11";
            this.activity11.Parameters = paras2;
    
    
            ActivityBind bind = new ActivityBind();
            bind.Name = activity11.Name;
            bind.Path = "Parameters[0].Value";
    
            activity12.Parameters[0].SetBinding(Parameter.ValueProperty, bind);
            // 
            // Workflow1
            // 
            this.Activities.Add(this.activity11);
            this.Activities.Add(this.activity12);
            this.Name = "Workflow1";
            this.CanModifyActivities = false;
    
        }
    
        #endregion
    
        private ActivityLibrary1.Activity1 activity12;
        private ActivityLibrary1.Activity1 activity11;
    
    • Edited by Ystlife Saturday, October 10, 2009 2:28 AM ss
    Saturday, October 10, 2009 2:24 AM

Answers

  • There isn't built in support for activity binding to elements of collections. You could create your own gui for this and associate it with your property via attributes but I can't remember the details of how to do that. You can bind entire collections using activity binding though.
    If my response answers your question, please mark it as the "Answer" by clicking that button above my post. My blog: http://www.RyanVice.net/
    Tuesday, October 13, 2009 1:37 PM
    Moderator

All replies

  • Monday, October 12, 2009 9:53 PM
    Moderator
  • Hi Dai,

    I think my issue is not how to write a custom worklfow activity, the key problem is how to set binding for generic property.
    For example,
    I have a generic dependency property just like List<Parameter>, and I want to set binding for one of the list items, like List<Parameter>[i].SetBindings...

    I am not sure if WF support settting bindings for this case.

    Thanks


    Share the point
    Tuesday, October 13, 2009 7:44 AM
  • There isn't built in support for activity binding to elements of collections. You could create your own gui for this and associate it with your property via attributes but I can't remember the details of how to do that. You can bind entire collections using activity binding though.
    If my response answers your question, please mark it as the "Answer" by clicking that button above my post. My blog: http://www.RyanVice.net/
    Tuesday, October 13, 2009 1:37 PM
    Moderator
  • Thanks, hope vs 2010 support it.
    Share the point
    Monday, October 19, 2009 11:17 AM