C# 如何为Windows工作流中的自定义活动指定属性编辑器?
我正在创建自定义活动列表,并希望指定单击省略号按钮时使用的编辑器。具体地说,我想为我的自定义活动的集合属性使用键/值属性网格类型编辑器 据我所知,我可以用EditorAttribute做到这一点。有我可以从中挑选的标准编辑器列表吗 编辑: 我试过:C# 如何为Windows工作流中的自定义活动指定属性编辑器?,c#,.net,workflow-foundation-4,workflow-foundation,C#,.net,Workflow Foundation 4,Workflow Foundation,我正在创建自定义活动列表,并希望指定单击省略号按钮时使用的编辑器。具体地说,我想为我的自定义活动的集合属性使用键/值属性网格类型编辑器 据我所知,我可以用EditorAttribute做到这一点。有我可以从中挑选的标准编辑器列表吗 编辑: 我试过: [Editor(typeof(System.ComponentModel.Design.CollectionEditor), typeof(System.Drawing.Design.UITypeEditor))] public InArgument
[Editor(typeof(System.ComponentModel.Design.CollectionEditor), typeof(System.Drawing.Design.UITypeEditor))]
public InArgument<string[]> Roles { get; set; }
及
第一种方法在单击省略号时为我提供了标准表达式编辑器,第二种方法确实为我提供了一个没有真正可编辑功能的属性网格行。来自以下文档:
编辑属性时,可视化设计器应创建新属性
通过对话框或下拉列表显示指定编辑器的实例
窗户
使用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;
}
}
查看UITypeEditor上的文档,然后查看从中派生的类。@MikeCheel,我可以将其与EditorAttribute一起使用吗?请阅读文档中的备注部分:我在搜索过程中找到了此页面,但无法获得任何不同的结果。关于我如何尝试使用EditorTributeAlRight的问题,请参见我的编辑。我想知道是否有我可以重复使用的编辑器。我已经能够扩展DialogPropertyValueEditor并以同样的方式使用它。但是,我在尝试让ExpressionEditor for variable assignment在我的网格中工作时遇到了困难。我想我无法重用在使用其他工作流活动时看到的任何编辑器。我一直在尝试构建自己的堆栈,但遇到了一个问题:您的另一篇堆栈文章没有显示从UITypeEditor继承的任何内容
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;
}
}