我正在构建自定义活动的列表,并希望指定单击省略号按钮时使用的编辑器。具体来说,我想将键/值属性网格类型编辑器用于自定义活动的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;
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句