簡體   English   中英

如何在Windows工作流中為自定義活動指定屬性編輯器?

[英]How Do I Specify A Property Editor for a Custom Activity in Windows Workflow?

我正在構建自定義活動的列表,並希望指定單擊省略號按鈕時使用的編輯器。 具體來說,我想將鍵/值屬性網格類型編輯器用於我的自定義活動的collection屬性。

據我了解,我可以使用EditorAttribute做到這一點。 我可以從中選擇標准編輯器嗎?

編輯:

我試過了:

[Editor(typeof(System.ComponentModel.Design.CollectionEditor), typeof(System.Drawing.Design.UITypeEditor))]
public InArgument<string[]> Roles { get; set; }

[Editor(typeof(System.ComponentModel.Design.CollectionEditor), typeof(System.Drawing.Design.UITypeEditor))]
public Collection<string> Roles { get; set; }

單擊省略號時,第一種方法為我提供了標准表達式編輯器,第二種方法卻為我提供了沒有真正可編輯功能的屬性網格行。

http://msdn.microsoft.com/zh-CN/library/system.componentmodel.editorattribute(v=vs.110).aspx的文檔中:

編輯屬性時,視覺設計者應通過對話框或下拉窗口創建指定編輯器的新實例。

使用EditorBaseTypeName屬性查找此編輯器的基本類型。 唯一可用的基本類型是UITypeEditor。

使用EditorTypeName屬性獲取與此屬性關聯的編輯器類型的名稱。

更多信息:我使用UITypeEditor的經驗是自定義tfs生成過程,但是對您來說應該沒有太大不同(我猜是這樣)。 我創建自定義對話框的方法是創建一個從UITypeEditor繼承的類,並重寫EditValue和GetEditStyle。

public class Editor : UITypeEditor
    {
        public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value)
        {               
            if (provider != null)
            {
                IWindowsFormsEditorService service = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

                if (service != null)
                {
                    using (MyEditorUIDialog dialog = new MyEditorUIDialog ())
                    {
                        DialogResult result = dialog.ShowDialog();
                        if (result == DialogResult.OK)
                            value = dialog.MyReturnValue;
                    }               
                }
            }       

            return value;
        }

        public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
        {
            return UITypeEditorEditStyle.Modal;
        }
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM