2009-10-09 91 views
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)); 
} 

//自定義活動與一般的財產

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; 

回答

1

我只是碰到了同樣的問題,我要解決它簡單地消除了收集的需要。

你可以做同樣很容易地:

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

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

然後,您可以綁定,爲你的依賴屬性,而不是名單。

2

作爲我以前的答案,我一直在這方面做一些額外的工作,雖然技術上可用並不是很理想。所以我想出了一個更好的解決方案。

基本上,當綁定屬性時,內置設計器'猜測'當您單擊屬性框中的省略號時要加載哪個控件。當你將它指向一個列表時,它會加載一些奇特的編輯器,讓你手動添加列表項,這對於任何類型的動態數據場景來說基本沒有用處。

我做了一些挖掘,跨越這個崗位絆倒:http://blogs.microsoft.co.il/blogs/bursteg/archive/2006/10/29/DynamicWorkflowBindingParameters.aspx

這不是正是我需要的,但它確實我的線索給編輯的屬性。

在「什麼,我需要知道」這個答案的一部分就在這裏,只是這個屬性添加到您的財產申報(實際的屬性,不是的DependencyProperty支持字段):

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

這將迫使加載依賴項屬性綁定接口的GUI。

這並不是工作流框架本身的一個缺點,但是如果要深入研究這個解決方案,這是一種惱人的做法。它似乎無處不在你與Windows工作流程,問題在那裏,但沒有答案。

無論如何,我希望這可以幫助你或其他人,如果你遇到這個問題。

相關問題