Workflow 如何在工作流基础上设置自定义活动的通用属性绑定

Workflow 如何在工作流基础上设置自定义活动的通用属性绑定,workflow,properties,generics,binding,Workflow,Properties,Generics,Binding,我有一个名为“参数”的自定义类和一个具有通用集合属性的自定义活动,称为“参数”,我想为参数属性的泛型列表中的一个参数设置绑定,我已经尝试了ActuviyBand,但是它不起作用,有没有办法用工作流基础来实现呢?请参阅以下代码: public class Parameter:DependencyObject //A Class { public string Name { get { return (string)GetValue(NameProperty); }

我有一个名为“参数”的自定义类和一个具有通用集合属性的自定义活动,称为“参数”,我想为参数属性的泛型列表中的一个参数设置绑定,我已经尝试了ActuviyBand,但是它不起作用,有没有办法用工作流基础来实现呢?请参阅以下代码:

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));
public类参数:DependencyObject//A类
{
公共字符串名
{
获取{return(string)GetValue(NameProperty);}
set{SetValue(NameProperty,value);}
}
//使用DependencyProperty作为Name的后备存储。这将启用动画、样式、绑定等。。。
公共静态只读DependencyProperty NameProperty=
DependencyProperty.Register(“名称”、类型(字符串)、类型(参数));
公共字符串值
{
获取{return(string)GetValue(ValueProperty);}
set{SetValue(ValueProperty,value);}
}
//使用DependencyProperty作为值的后备存储。这将启用动画、样式、绑定等。。。
公共静态只读从属属性ValueProperty=
Register(“Value”、typeof(string)、typeof(Parameter));
}
//具有泛型属性的自定义活动
公共分部类活动1:System.Workflow.ComponentModel.Activity
{
公共活动1()
{
初始化组件();
}
受保护的覆盖ActivityExecutionStatus执行(ActivityExecutionContext executionContext)
{
返回base.Execute(executionContext);
}
公共列表参数
{
获取{return(List)GetValue(ParametersProperty);}
set{SetValue(参数属性,值);}
}
//使用DependencyProperty作为参数的后备存储。这将启用动画、样式、绑定等。。。
公共静态只读从属属性参数属性=
DependencyProperty.Register(“参数”、类型(列表)、类型(活动1));
//设计者代码

   #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;
#区域设计器生成的代码
///  
///设计器支持所需的方法-不修改
///此方法的内容与代码编辑器一起使用。
/// 
[System.Diagnostics.DebuggerNonUserCode]
私有void InitializeComponent()
{
this.CanModifyActivities=true;
this.activity12=新建ActivityLibrary1.Activity1();
this.activity11=新ActivityLibrary1.Activity1();
列表1=新列表();
paras1.Add(新参数(){Name=“a”,Value=“a”});
1.添加(新参数(){Name=“b”,Value=“b”});
列表2=新列表();
添加(新参数(){Name=“c”,Value=“c”});
添加(新参数(){Name=“d”,Value=“d”});
// 
//活动12
// 
this.activity12.Name=“activity12”;
this.activity12.Parameters=1;
// 
//活动11
// 
this.activity11.Name=“activity11”;
this.activity11.Parameters=2;
ActivityBind=新ActivityBind();
bind.Name=activity11.Name;
bind.Path=“参数[0].Value”;
activity12.Parameters[0].SetBinding(Parameter.ValueProperty,绑定);
// 
//工作流程1
// 
this.Activities.Add(this.activity11);
this.Activities.Add(this.activity12);
this.Name=“Workflow1”;
this.CanModifyActivities=false;
}
#端区
私人活动图书馆1.活动1.活动12;
私人活动图书馆1.活动1.活动11;

我刚刚遇到了同样的问题,我通过简单地消除收集的需要来解决它

你可以很容易地做到这一点:

public class Parameters {
  private Dictionary<string, string> _parameters;

  public void Add(string name, string value) {
    _parameters.Add(name, value);
  }
}
公共类参数{
私有字典参数;
公共void添加(字符串名称、字符串值){
_参数。添加(名称、值);
}
}

然后可以将其绑定到依赖项属性而不是列表。

我刚刚遇到了同样的问题,我通过简单地消除对集合的需要来解决它

你可以很容易地做到这一点:

public class Parameters {
  private Dictionary<string, string> _parameters;

  public void Add(string name, string value) {
    _parameters.Add(name, value);
  }
}
公共类参数{
私有字典参数;
公共void添加(字符串名称、字符串值){
_参数。添加(名称、值);
}
}

然后,您可以将其绑定到依赖项属性,而不是列表。

我在这方面做了一些额外的工作,作为我以前的回答,尽管技术上可用性并不理想。因此,我提出了一个更好的解决方案

基本上,在绑定属性时,当您单击属性框中的省略号时,内置设计器会“猜测”要加载哪个控件。当您将其指向列表时,它会加载一些奇特的编辑器,允许您手动添加列表项,这对于任何类型的动态数据场景基本上都是无用的

我做了一些挖掘,在这根柱子上绊倒了:

这并不完全是我所需要的,但它确实为我提供了编辑器属性的线索

此答案的“我需要知道什么”部分在这里,只需将此属性添加到属性声明中(实际属性,而不是DependencyProperty支持字段):

这将迫使GUI加载依赖项属性绑定接口

这并不是工作流框架本身的一个缺点,但要深入研究这个问题以找出解决方案,这有点烦人。似乎在使用windows workflow的任何地方,都有问题,但没有答案


无论如何,如果你遇到这个问题,我希望这能对你或其他人有所帮助。

作为我之前的回答,我在这方面做了一些额外的工作,尽管技术上的可用性并不理想。所以我想出了一个更好的解决方案

基本上,在绑定属性时,当您单击中的省略号时,内置设计器“猜测”要加载哪个控件