示例#1
0
        protected override void DrawCore(DrawingContext drawingContext, DrawingAttributes drawingAttributes)
        {
            if (drawingContext == null)
            {
                throw new ArgumentNullException("drawingContext");
            }
            if (null == drawingAttributes)
            {
                throw new ArgumentNullException("drawingAttributes");
            }
            Pen pen = new Pen
            {
                StartLineCap = PenLineCap.Round,
                EndLineCap = PenLineCap.Round,
                Brush = new SolidColorBrush(drawingAttributes.Color),
                Thickness = drawingAttributes.Width
            };

            BrushConverter bc = new BrushConverter();
            Brush BackGround = (Brush)bc.ConvertFromString(drawingAttributes.GetPropertyData(DrawAttributesGuid.BackgroundColor).ToString());
            GeometryConverter gc = new GeometryConverter();
            Geometry geometry = (Geometry)gc.ConvertFromString(string.Format("M {0},{1} {2},{3} {4},{5} Z", StylusPoints[0].X, StylusPoints[1].Y, (Math.Abs(StylusPoints[1].X - StylusPoints[0].X))/2 + StylusPoints[0].X, StylusPoints[0].Y, StylusPoints[1].X, StylusPoints[1].Y));
            GeometryDrawing gd = new GeometryDrawing(BackGround, pen, geometry);
            drawingContext.DrawDrawing(gd);
        }
        public void NewMethod()
        {
            //#region create method 1

            //Path path = new Path();

            //PathGeometry pathGeometry = new PathGeometry();

            //PathFigure pathFigure = new PathFigure();

            //pathFigure.StartPoint = new Point(400, 300);

            //PathSegmentCollection segmentCollection = new PathSegmentCollection();

            //segmentCollection.Add(new LineSegment() { Point = new Point(600, 100) });

            //pathFigure.Segments = segmentCollection;

            //pathGeometry.Figures = new PathFigureCollection() { pathFigure };

            //path.Data = pathGeometry;

            //path.Stroke = new SolidColorBrush(Colors.BlueViolet);

            //path.StrokeThickness = 3;

            //main.Children.Add(path);

            //#endregion

            //#region create method2

            //Path pp = new Path();

            //pp.Stroke = new SolidColorBrush(Colors.Blue);

            //pp.StrokeThickness = 3;

            //StreamGeometry geometry = new StreamGeometry();

            //geometry.FillRule = FillRule.Nonzero; //声前F0还是F1,现在是F1

            //using (StreamGeometryContext ctx = geometry.Open())

            //{

            //    ctx.BeginFigure(new Point(30, 60), true, true);

            //    ctx.LineTo(new Point(150, 600), true, false);

            //}

            //geometry.Freeze();

            //pp.Data = geometry;

            //main.Children.Add(pp);

            //#endregion

            #region create method3

            Path pp3 = new Path();

            //pp3.Data

            pp3.Stroke = new SolidColorBrush(Colors.Red);

            pp3.StrokeThickness = 3;

            GeometryConverter gc = new GeometryConverter();

            pp3.Data = (Geometry)gc.ConvertFromString("M 20,30 500,100");

            main.Children.Add(pp3);

            #endregion
        }