首先,我想知道这是否可能。我在互联网上读到了关于这个的轻微抱怨,但我并不完全确定。
我的场景:我有一个基本图表类,它有一些所有图表都应该有的方法。
public partial class BaseChart : System.Web.UI.UserControl
{
public BaseChart()
{
}
public void ToggleLegend()
{
Chart1.Legends[0].Enabled = !Chart1.Legends[0].Enabled;
}
}
此 BaseChart 也有一些标记——设置背景颜色等。继承 BaseChart 的所有图表都应使用此起始标记并能够在此基础上进行构建。
然后我想这样做:
public partial class HistoricalLineChart : BaseChart
{
public HistoricalLineChart()
: base()
{
}
public HistoricalLineChart(int reportID)
: base()
{
Chart1.Titles[0].Text = "Hello World";
}
}
其中 HistoricalLineChart 是一个没有标记的 Web 用户控件,例如“HistoricalLineChart.ascx”
问题是 Chart1 在 HistoricalLineChart 的范围内是未定义的。我在这里缺少什么吗?
谢谢。