Is there some open source code already written out there somewhere that will accept a class with properties and validation attributes, and output a Windows form with controls that correspond to those properties?
Examples:
public bool IsRed { get; set; }
produces a checkbox with an Is Red?
label.
public int NumberOfDays { get; set; }
produces a text box with a label called Number of Days
and restricts input to numeric characters only.
[Required]
public Color Color { get; set; }
where Color is an enum of the form
public enum Color
{
Red,
Green,
Blue
}
produces a combo box with the list populated with Red
Green
and Blue
, and makes it required.
Ideally, the generated code includes a method that accepts an instance of my class and prepopulates the controls in the winform with the values in the properties of my instance. Correspondingly, another method saves the existing values in the controls to an instance of my class.
Is there something like that available?
Please note: I am not looking for:
It is 'quite easy' to extract the functionality of the PropertyGrid
into your own hosted controls, but that would only cover half your requirement. At a minimum, read up on TypeConverter
, TypeDescriptor
and PropertyDescriptor
.
Also have a look at: codeproject.com/KB/custom-controls/xacc_propertygrid.aspx, this basically exposes the PropertyGrid
's functionality to a web page, but it will give you some ideas.
I know this is not a complete answer, but should point one in the right direction to write/author such a tool.
It would be nice if such a scaffolding tool existed for WinForms :)
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