如何在Windows应用商店中绘制一条线

时间:2015-11-17 10:54:55

标签: visual-studio-2013 windows-store-apps line

我正在尝试创建一个应用程序,该应用程序应包含按下键盘键时绘制的线条。当按下键盘上的左箭头时,该线应向左移动。当按下键盘上的右箭头时,相应的线应向右移动。

我认为可以使用Path课程,但我不知道如何实施。即使我不知道如何启动代码。你能指导我如何在windows商店应用程序中画线。

1 个答案:

答案 0 :(得分:0)

private PathGeometry DrawGeometry()
    {

        bool largeArc = WedgeAngle > 180.0;
        Size outerArcSize = new Size(Radius, Radius);
        Size innerArcSize = new Size(InnerRadius, InnerRadius);

        Point innerArcStartPoint = Utilities.ComputeCartesianCoordinate(RotationAngle, InnerRadius);
        Point ButtomLineEndPoint = Utilities.ComputeCartesianCoordinate(RotationAngle, Radius);
        Point OuterArcEndPoint = Utilities.ComputeCartesianCoordinate(RotationAngle + WedgeAngle, Radius);
        Point EndLineEndPoint = Utilities.ComputeCartesianCoordinate(RotationAngle + WedgeAngle, InnerRadius);


        innerArcStartPoint.X += CentreX;
        innerArcStartPoint.Y += CentreY;
        ButtomLineEndPoint.X += CentreX;
        ButtomLineEndPoint.Y += CentreY;
        OuterArcEndPoint.X += CentreX;
        OuterArcEndPoint.Y += CentreY;
        EndLineEndPoint.X += CentreX;
        EndLineEndPoint.Y += CentreY;


        PathFigure path = new PathFigure();
        path.StartPoint = innerArcStartPoint;


        ArcSegment InnerArc = new ArcSegment();
        InnerArc.Size = innerArcSize;
        InnerArc.SweepDirection = SweepDirection.Counterclockwise;
        InnerArc.Point = innerArcStartPoint;
        InnerArc.IsLargeArc = largeArc;

        LineSegment ButtomLine = new LineSegment();
        ButtomLine.Point = ButtomLineEndPoint;
        ArcSegment OuterArc = new ArcSegment();
        OuterArc.SweepDirection = SweepDirection.Clockwise;
        OuterArc.Point = OuterArcEndPoint;
        OuterArc.Size = outerArcSize;
        OuterArc.IsLargeArc = largeArc;
        LineSegment EndLine = new LineSegment();
        EndLine.Point = EndLineEndPoint;
        path.Segments.Add(ButtomLine);
        path.Segments.Add(OuterArc);
        path.Segments.Add(EndLine);
        path.Segments.Add(InnerArc);

        PathGeometry myPath = new PathGeometry();
        myPath.Figures.Add(path);
        return myPath;
    }

此代码将为您绘制一个Pie切片,因为我正在构建PieChart它包含线条曲线等。它将节省您的大量时间