繁体   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