Passing objects to a UITypeEditor

Posted by Kath on Stack Overflow See other posts from Stack Overflow or by Kath
Published on 2009-06-18T03:18:10Z Indexed on 2010/05/19 10:50 UTC
Read the original article Hit count: 269

Filed under:
|
|

I am currently hoping to use a PropertyGrid to allow users to edit some of my classes, however I've hit a wall with passing objects to the UITypeEditor(s) they use. When the user presses the drop down I want to show a listbox of already loaded textures to choose from, if they want to use a texture the application hasn't loaded yet they can click a button to choose one from a file dialog. In case I make no sense here a mock of the form:

Dropdown Image.

My problem: To fill the listbox I need access to the class that manages the list of resources from the UITypeEditor.

Now I've solved this problem for my own classes by giving them a reference on creation to their managing object. In the UITypeEditor I then use that reference to access what I need. However I can't do this for classes I haven't written, such as the XNA Texture2D class.

Here are what the classes I'm using look like:

class StaticGeometryChunk
{
    // Geometry data to draw with. Contains a reference to its managing 
    // class for use in its UITypeEditor.
    public GeometryData { get; set; }
    ....
}

class Material
{
    // These are XNA classes. I can't just add a reference to its managing 
    // class (I think?).
    public Texture2D Texture1 { get; set; }
    public Texture2D Texture2 { get; set; }
    ....
}

I've been looking at my options and they seem to be:

  1. Make the managing classes static.

I don't really want to do this. There are several managing classes as each resource is loaded differently. There are also classes that need to be created before these and are passed in.

  1. Make the managing classes singletons.

I don't really want to do this either. It seems like a quick and dirty way to "hide" the problem instead of "solve" it. I also might want the option of having several managing classes in the future which the singletons eliminate.

  1. Create a wrapper class which holds the reference to a managing class and its target (such as the XNA Texture2D).

This is currently what I'm thinking of doing. Its would be quite simple and quick to do but something about it nags me but I don't know what.

Any thoughts on the above or other methods to pass what I need into the UITypeEditor?

Thank you for reading.

© Stack Overflow or respective owner

Related posts about c#

Related posts about propertygrid