我希望绘制图形的所有操作都在我的控制之下,继承自Canvas。但窗口不显示MyCanvas。我不知道为什么。
class MyCanvas : Canvas
{
private Double XTimeScale;
private Double YAmpSacle;
private Double YTopLimit;
private Double YBotLimit;
private List<Point> DotsGraph;
public MyCanvas(Double XTimeScale,
Double YAmpSacle,
Double YTopLimit,
Double YBotLimit)
{
this.XTimeScale = XTimeScale;
this.YAmpSacle = YAmpSacle;
this.YTopLimit = YTopLimit;
this.YBotLimit = YBotLimit;
this.Height = (YTopLimit + YBotLimit);
}
public List<Line> DrawNet(Double Width, Double Height)
{
List<Line> temp = new List<Line>();
SolidColorBrush brush = new SolidColorBrush();
brush.Color = Colors.Gray;
for (int i = 0; i < Width; i+= 10)
{
Line Y = new Line();
Y.Stroke = brush;
Y.StrokeThickness = 1;
Y.Y1 = 0;
Y.Y2 = Height;
Y.X1 = i;
Y.X2 = i;
temp.Add(Y);
}
for (int j = 0; j < Height; j += 10)
{
Line X = new Line();
X.Stroke = brush;
X.StrokeThickness = 1;
X.X1 = 0;
X.X2 = Width;
X.Y1 = j;
X.Y2 = j;
temp.Add(X);
}
foreach (var t in temp)
this.Children.Add(t);
return temp;
}
}
应该显示MyCanvas的窗口类。我把它添加到Grid:
public partial class ShowCanvas : Window
{
public ShowCanvas()
{
InitializeComponent();
MyCanvas EAP = new MyCanvas(300, 300, 300, 300);
Base.Children.Add(EAP); // Base is Grid on window ShowCanvas
}
}