[Editor("Design.ListControlStringCollectionEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))] public List<string> Item //{ get; set; } { get {return _Item; } set {_Item = value; }//当编辑属性完成按确定键时没有触发该函数,本人该去哪里取本人在属性栏里编辑好的值呢?
解决方案
5
不触发是正常的,VS自带的集合编辑器是不触发set的,他可能用的是Add方法吧数据添加到你的list中的,所以目前你的list可以得到数据但是不会触发set。你要是硬想触发的话,你可以自定义一个集合编辑器,这样就可以触发set
15
[BrowsableAttribute(true)] [DescriptionAttribute("图片集合")] //下面这句声明你的自定义集合属性编辑器 [EditorAttribute(typeof(ImageEditor), typeof(UITypeEditor))] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public Dictionary<string, Image> Images { get { return Images1; } set { Images1 = value; } }
然后在自定义你的编辑器
internal class ImageEditor : UITypeEditor { public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context) { return UITypeEditorEditStyle.Modal; } public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value) { IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); if (edSvc != null) { //这里的GetImageList是你自定义的Form窗口 GetImageList rc = new GetImageList(); ImageList control = (ImageList)context.Instance; rc.Images1 = control.Images1; rc.ShowDialog(); value = rc.Images1; } return value; } }
大致就这样 你可以写个例子看看