Search code examples
c#.netcollectioneditor

CollectionEditor's Parent


I have a property like that:

[Editor(typeof(LayerCollection), typeof(UITypeEditor))]
public List<Layer> Layers { get { return layers; } }

And I have a LayerCollection class that derived from CollectionEditor. And this Layers property is in Canvasclass. Now, the Layer object needs to know about Canvas class which is the parent of the collection. So how can I get the parent of the CollectionEditor named LayerCollection?

Or if it is impossible, can I pass a parameter to the CollectionEditor when it is created? By this way I can pass the Canvas object as a parameter to the Layer when it is created.


Solution

  • "Hans Passant" answered my question in the first post's comment:

    The first argument to EditValue() is an ITypeDescriptorContext that gives you the context you need. Its Instance property references the control. – Hans Passant