Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Designer does not generate code for a property of a subcontrol. Why?

I created SubCtrl inheriting UserControl. It has no code. I created then Ctrl, which also inherits UserControl. It has a SubCtrl in it and its only code means to expose it publicly so it appears in the property list of Ctrl:

public subctrl.SubCtrl SUBCTRL
{
    get { return this.subCtrl1; }
}

Then I created a simple Form project which only has a Ctrl in it and no code. As I wanted, SUBCTRL appears in the property list of Ctrl so I can change things. I changed the background color (say, to red), and the subctrl turned red in the designer.

But magically, when I run the project, it turns back to the standard gray. It appears that no code is generated in Form1.Designer.cs to change SUBCTRL's back color to red. If I write it by hand, it works, but that's not what I want. It should be automatic, obviously.

The Ctrl, on the other hand, behaves normally. The code is generated and everything works happily.

What's wrong with the subcontrol?

like image 593
Gabriel Avatar asked Sep 13 '10 14:09

Gabriel


1 Answers

Add [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] to the property.

like image 101
SLaks Avatar answered Nov 03 '22 08:11

SLaks