Hello this is my first question of stack overflow, so forgive me if i do anything stupid. Well my problem is that I'm working on a level editor and i want to use a PropertyGrid control to edit properties of tiles/entities etc.. so everything works so far, the values show correctly, update when changed trough code but the problem i am expierencing is that I cannot change values unless it is a boolean, i googled alot but i simply could find no solutions.
Here is the code where i define the properties:
[Description("Defines the Position on the screen")]
public Vector2 screenpos { get; set; }
Vector2 WorldPos;
[Description("Defines the texture of the selected tile")]
public string texture { get; set; }
[Description("Defines if the player can collide with this tile")]
public bool IsCollidable { get; set; }
[Description("Defines on what layer this tile is drawn (1-3)")]
public int Layer { get; set; }
[Description("Shows if the tile is currently visible on the screen")]
public bool OnScreen { get; private set; }
I can edit the IsCollidable and if i remove the private from OnScreen's set i can edit that too but i can not edit anything else, oh and i would appriciate if you could word your answers a bit simpler i'm not that much of an expierenced programmer, thanks in advance.
Most standard types with a public property (that is read+write) should be editable.
If Vector2
is fairly simple, and you just want it to expand in the PropertyGrid
, then:
[Description("Defines the Position on the screen")]
[TypeConverter(typeof(ExpandableObjectConverter))]
public Vector2 screenpos { get; set; }
If Vector2
is your own code, then you can also decorate Vector2
itself and it will apply to all properties:
[TypeConverter(typeof(ExpandableObjectConverter))]
public {class|struct} Vector2 {...}
There is also a trick to do this for types outside of your control; at app startup, run:
TypeDescriptor.AddAttributes(typeof(Vector2),
new TypeConverterAttribute(typeof(ExpandableObjectConverter)));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With