ASP.NET自定义控件与复杂属性

3

我正在开发一个自定义控件(4.0),并且想知道如何在不重写业务类的情况下将其作为属性进行重用。

我在业务层程序集中有一组类(简化版):

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;
        }

        ...
    }
}

但这样做我就无法在MapOptions标签的内部部分查看LatLng(以及其他作为MapOptions属性使用的类)的属性。只能作为属性。因此,在标记中,我可以写:

<rec:MyControl ID="control1" runat="server" Width="900" Height="500">
    <MapOptions Center="" />
</rec:MyControl>

但是这样我会失去对所有由LatLng公开的智能感知,我正在寻找一种解决方案来获得它:

<rec:MyControl ID="control1" runat="server" Width="900" Height="500">
    <MapOptions>
        <Center Lat="12.0" Lng="2.0" />
    </MapOptions>
</rec:MyControl>

有什么建议吗?
1个回答

0

尝试向public class LatLng添加标记[DesignerSerializationVisibility(DesignerSerializationVisibility.Content), PersistenceMode(PersistenceMode.InnerProperty)]


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接