开发者

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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜