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

我是研究僧i 提交于 2019-12-12 10:43:22

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/3701142/designer-does-not-generate-code-for-a-property-of-a-subcontrol-why

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!