[WebControl开发]如何persist控件的collection类型的属性(property)?
我正在开发Asp.net的WebControl.
我的控件类有一个属性Items是ComboItemCollection类型(CollectionBase),其中的Item类型为ComboItem对象.
我写了相应的ComboItemCollectionEditor以支持Property Explorer的属性编辑,写了ComboItemConverter以支持ComboItem的类型转换。
Items的Meta Attributes如下:
[NotifyParentProperty(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Editor(typeof(ComboItemCollectionEditor),typeof(UITypeEditor))]
[PersistenceMode(PersistenceMode.InnerDefaultProperty)]
出现问题的情况是:
我在Property Explorer中添加了ComboItem给Items,这时.net的Designer会生成相应的Aspx的代码如下:
<CC1:MyControl>
<Items>
<CC1:ComboItem value="1" content="1" ....其他attributes></CC1:ComboItem>
<CC1:ComboItem value="2" content="2" ....其他attributes></CC1:ComboItem>
<CC1:ComboItem value="3" content="3" ....其他attributes></CC1:ComboItem>
</Items>
</CC1:MyControl>
然后我编译整个项目,此时控件的UI无法绘制,提示信息是"Cannot set on Items".但是Run起来,整个控件却没有问题,添加的Items也是正确的值。
请问:
是什么原因导致我的控件在DesignTime不可绘制?是Items没有相应的TypeConvertor还是Items的Meta Attributes不正确?