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>
有什麼建議嗎?