Attribute for accessing custom properties in Forms Designer
I have a control that has a list of Rods. The Rods have a few public properties:
public class Rod
{
float Angle { get; set; }
Color MainColour { get; set; }
int Length { get; set; }
int Width { get; set; }
//other private code here you need not be concerned with ;)
}
In the control that hosts the Rods, the list is declared as:
public List<Rod> Rods { get; set; }
I would like to be able to select a RodsHost control and click on the "Rods" property page, and edit the Rods on that control through the Forms Designer GUI. Currently, I can add Rods to the list, but not edit the Rod's properties (Angle, MainColour, etc...). I tried applying the attribute [DesignTimeVisible(true)]
to the Rods class, that didn't seem to work. I thought maybe I should use the Designer attribute, bu开发者_运维知识库t I'm not sure which Designer class I need here. Anyone got a suggestion?
I don't know if this helps you out or not but what I did was create a userControl and within it created the properties as get set. The properties then showed up automatically in the Properties pane in the visual IDE.
It looks like I needed to decorate the list as:
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
as well as add a constructor to set some appropriate default values.
精彩评论