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

发布于 2024-08-06 18:15:21 字数 3573 浏览 3 评论 0原文

我有一个名为“Parameter”的自定义类和一个具有名为“Parameters”的通用集合属性的自定义活动,我想为参数属性的通用列表中的参数之一设置绑定,我尝试过使用activitybind,但它是不起作用,有什么办法可以使用工作流基础来做到这一点吗?请参阅下面的代码:

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));

//设计师代码

   #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;

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;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

如果没结果 2024-08-13 18:15:21

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

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

我做了一些挖掘并绊倒了这篇文章: http://blogs.microsoft.co.il/blogs/bursteg/archive/2006/10/29/DynamicWorkflowBindingParameters.aspx

这并不完全是我所需要的,但它确实让我了解了 Editor 属性。

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

[Editor(typeof(BindUITypeEditor), typeof(UITypeEditor))]

这将强制 GUI 加载依赖属性绑定接口。

这实际上并不是工作流框架本身的缺点,但必须深入研究这个问题才能找出解决方案,这有点烦人。似乎无论你在 Windows 工作流程中遇到什么问题,问题都在那里,但没有答案。

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

I've been doing some additional work in this area as my previous answer, although technically usable isn't really ideal. So I've come up with a better solution.

Basically, when binding properties, the built in designer 'guesses' as to which control to load up when you click the ellipsis in the property box. When you point it to a list, it loads up some fancy editor that lets you manually add list items, which is basically useless for any sort of dynamic data scenarios.

I did some digging and tripped across this post: http://blogs.microsoft.co.il/blogs/bursteg/archive/2006/10/29/DynamicWorkflowBindingParameters.aspx

It wasn't exactly what I needed, but it did clue me in to the Editor attribute.

The 'what do I need to know' part of this answer is here, simply add this attribute to your property declaration (the actual property, not the DependencyProperty backing field):

[Editor(typeof(BindUITypeEditor), typeof(UITypeEditor))]

That will force the GUI to load up the dependency property binding interface.

This isn't really a shortcoming of the workflow framework itself, but it was kind of annoying to have to dig into this so deeply to figure out the solution. It just seems everywhere you turn with windows workflow, the questions are there but not the answers.

Anyways, I hope this helps you or someone else if you run into this issue.

泪是无色的血 2024-08-13 18:15:21

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

您可以很容易地执行相同的操作:

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

  public void Add(string name, string value) {
    _parameters.Add(name, value);
  }
}

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

I just ran into this same issue and I solved it by simply eliminating the need for the collection.

You could do the same pretty easily:

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

  public void Add(string name, string value) {
    _parameters.Add(name, value);
  }
}

You can then bind that to your dependency property instead of the list.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文