This is a slightly tricky one; the solution involves building with the full .NET Framework (since the client-only framework doesn't include System.Design
). You need to create your own subclass of CollectionEditor
and tell it what to do with the temporary collection after the UI is finished with it:
public class SomeTypeEditor : CollectionEditor {
public SomeTypeEditor(Type type) : base(type) { }
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) {
object result = base.EditValue(context, provider, value);
// assign the temporary collection from the UI to the property
((ClassContainingStuffProperty)context.Instance).Stuff = (List<SomeType>)result;
return result;
}
}
Then you have to decorate your property with the EditorAttribute
:
[Editor(typeof(SomeTypeEditor), typeof(UITypeEditor))]
public List<SomeType> Stuff {
// ...
}
Long and convoluted, yes, but it works. After you click "OK" on the collection editor popup, you can open it again and the values will remain.
Note: You need to import the namespaces System.ComponentModel
, System.ComponentModel.Design
and System.Drawing.Design
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…