线形和Shenanigans

时间:2012-06-27 14:45:50

标签: c# wpf

所以,基本上我试图在2个椭圆的中心之间画一条线

我认为应该这样做:

Path myPath = new Path();
myPath.Stroke = System.Windows.Media.Brushes.Black;     
myPath.StrokeThickness = 4;
myPath.HorizontalAlignment = HorizontalAlignment.Left;
myPath.VerticalAlignment = VerticalAlignment.Center;
EllipseGeometry myEllipseGeometry = new EllipseGeometry();
myEllipseGeometry.Center = new System.Windows.Point((xQuard * 10) + 100, yQuard * 10);
myEllipseGeometry.RadiusX = 2;
myEllipseGeometry.RadiusY = 2;
myPath.Data = myEllipseGeometry;
GraphPanel.Children.Add(myPath);

//if it's not the first point...
if (prevA != 0.0)
{
Path iLine = new Path();
iLine.Stroke = Brushes.Black;
iLine.StrokeThickness = 4;
iLine.HorizontalAlignment = HorizontalAlignment.Left;
myPath.VerticalAlignment = VerticalAlignment.Center;
LineGeometry iLineGeometry = new LineGeometry();

iLineGeometry.StartPoint = myEllipseGeometry.Center;

iLineGeometry.EndPoint = new System.Windows.Point(prevA, prevB);

iLine.Data = iLineGeometry;
GraphPanel.Children.Add(iLine);

}

//Set the previous point(s)
prevA = (xQuard * 10) + 100;
prevB = yQuard * 10;

现在你可以看到,我已经将Line的StartPoint =设置为第一个椭圆起点

然而...... enter image description here

为什么画面中的Line起点不是左侧点的中心?

1 个答案:

答案 0 :(得分:3)

我认为你的意思是iLine.VerticalAlignment而不是myPath.VerticalAlignment第二次,对吗?