【发布时间】:2016-09-19 10:50:12
【问题描述】:
我正在尝试在 WF 4.5 工作流活动中实现浏览文件夹,但省略号按钮没有显示,几乎没有任何反应。
这是我的 UITypeEditor 类:
public class BrowseForFolderEditor : UITypeEditor
{
public override object EditValue(ITypeDescriptorContext context,
IServiceProvider provider, object value)
{
string folderName = string.Empty;
BrowseForFolderAttribute browseForFolderAttribute = null;
if (value is string)
{
if (context?.PropertyDescriptor != null)
{
browseForFolderAttribute =
(BrowseForFolderAttribute)
context.PropertyDescriptor.Attributes[typeof(BrowseForFolderAttribute)];
}
var browse = new FolderBrowserDialogEx
{
Description = browseForFolderAttribute?.Description,
ShowNewFolderButton = true,
ShowEditBox = true,
SelectedPath = folderName,
ShowFullPathInEditBox = false,
RootFolder = Environment.SpecialFolder.MyComputer
};
var result = browse.ShowDialog();
if (result == DialogResult.OK)
folderName = browse.SelectedPath;
return folderName;
}
// Return whatever value if it wasn't a string - Should never occur!
return value;
}
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.Modal; //base.GetEditStyle(context);
}
public class BrowseForFolderAttribute : Attribute
{
public BrowseForFolderAttribute(string description)
{
this.Description = description;
}
public string Description { get; set; }
}
}
这就是我在Activity 中声明代码的方式:
[Description("Select the folder where the files will be
copied/moved to.")]
[Category("Folders")]
[Browsable(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[BrowseForFolderEditor.BrowseForFolder("Select the folder where the files will be
copied/moved to.")]
[Editor(typeof(BrowseForFolderEditor), typeof(UITypeEditor))]
public string TargetPath { get; set; }
我不知道这是否有任何区别,但我的工作流程 Activity 是 NativeActivity 类型。
该属性显示在属性网格中,但它只是显示为一个没有省略号按钮的文本框。
任何帮助将不胜感激。
UPDATE-1:
问题与它是 NativeCodeActivity 的事实没有任何关系,因为我刚刚将代码更改为 CodeActivity 并且没有任何区别。
【问题讨论】:
标签: c# workflow-foundation-4 workflow-foundation uitypeeditor