如何在Windows工作流中为自定义活动指定属性编辑器?

时间:2014-03-11 16:29:32

标签: c# .net workflow-foundation-4 workflow-foundation

我正在构建自定义活动列表,并希望指定单击省略号按钮时使用的编辑器。具体来说,我想将键/值属性网格类型编辑器用于我的自定义活动的集合属性。

根据我的理解,我可以使用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; }

第一种方法在点击省略号时给了我标准的表达式编辑器,第二种方法给了我一个没有真正可编辑功能的属性网格行。

1 个答案:

答案 0 :(得分:0)

来自http://msdn.microsoft.com/en-us/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;
        }
    }
相关问题