none
WPF InkCanvas RRS feed

  • 问题

  • 现在使用

     /// <summary>
            /// 画扇形
            /// </summary>
            /// <param name="point">圆心</param>
            /// <param name="wedgeAngle">角度</param>
            /// <param name="radius">半径</param>
            /// <param name="rotateAngle">整体旋转角度</param>
            /// <returns></returns>
            protected Geometry DefiningGeometry(Point point, double wedgeAngle, double radius, double rotateAngle,bool isLarge)
            {
                StreamGeometry geometry = new StreamGeometry();
                geometry.FillRule = FillRule.EvenOdd;

                using (StreamGeometryContext context = geometry.Open())
                {
                    Point outerArcStartPoint = ComputeCartesianCoordinate(90.0 + rotateAngle, radius);
                    outerArcStartPoint.Offset(point.X, point.Y);

                    Point outerArcEndPoint = ComputeCartesianCoordinate(90.0 + wedgeAngle + rotateAngle, radius);
                    outerArcEndPoint.Offset(point.X, point.Y);


                    bool largeArc = wedgeAngle > 180.0;

                    Size outerArcSize = new Size(radius, radius);
                    DrawGeometry(context, point, outerArcStartPoint, outerArcEndPoint, outerArcSize, largeArc,isLarge);
                }

                geometry.Freeze();
                return geometry;
            }

            /// <summary>
            /// 扇形画法
            /// </summary>
            protected virtual void DrawGeometry(StreamGeometryContext context, Point innerStartPoint, Point outerStartPoint, Point outerEndPoint, Size outerSize, bool largeArc, bool isLarge)
            {        
                context.BeginFigure(innerStartPoint, true, true);
                context.LineTo(outerStartPoint, true, true);
                context.ArcTo(outerEndPoint, outerSize, 0, largeArc, SweepDirection.Clockwise, true, true);
                context.LineTo(innerStartPoint, true, true);
            }

            /// <summary>
            /// Converts a coordinate from the polar coordinate system to the cartesian coordinate system.
            /// </summary>
            public Point ComputeCartesianCoordinate(double angle, double radius)
            {
                double angleRad = (Math.PI / 180.0) * (angle - 90);

                double x = radius * Math.Cos(angleRad);
                double y = radius * Math.Sin(angleRad);

                return new Point(x, y);
            }

    绘制一个Geometry ,并通过InkCanvas的

    protected override void DrawCore(DrawingContext drawingContext, DrawingAttributes drawingAttributes)

    {

    drawingContext.DrawGeometry(
                    null,
                    GetPen(GUIDConst.LineColor, GUIDConst.LineThickness),//画笔
                    上面绘制的Geometry );

    },可以显示,但InkCanvas选中拖动效果就没有了,请问如何解决

    2012年4月30日 14:07

答案