3
我正在开发自定义控件(4.0),并且我想知道如何重用业务类作为属性而不重写它。具有复杂属性的ASP.NET自定义控件
我有一组类的在我的业务层组件(简体):
public class LatLng
{
public decimal Lat { get; set; }
public decimal Lng { get; set; }
}
public class MapOptions
{
...
public LatLng Center { get; set; }
...
}
etc...
我想是重用的MapOptions类财产,我自定义的控制是一样的东西:
public class MyControl : WebControl
{
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content), PersistenceMode(PersistenceMode.InnerProperty)]
public MapOptions MapOptions
{
...
get
{
return this.ViewState["MapOptions"] as MapOptions;
}
set
{
this.ViewState["MapOptions"] = value;
}
...
}
}
但是通过这种方式,我无法看到LatOng(以及MapOptions用作属性的其他类)的属性作为MapOptions标记的内部部分。只作为属性。 所以在标记,我能写:
<rec:MyControl ID="control1" runat="server" Width="900" Height="500">
<MapOptions Center="" />
</rec:MyControl>
但这种方式我失去了所有的经纬度暴露的智能感知,我在寻找一个解决方案,以获得此:
<rec:MyControl ID="control1" runat="server" Width="900" Height="500">
<MapOptions>
<Center Lat="12.0" Lng="2.0" />
</MapOptions>
</rec:MyControl>
有什么建议吗?