WPF DrawGeometry不绘制笔触 [英] WPF DrawGeometry does not draw stroke

查看:556
本文介绍了WPF DrawGeometry不绘制笔触的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望这个问题以前没有问过,我到处搜索.

I hope this question was not asked before, I searched everywhere.

我的问题是我在wpf用户控件上用点绘制了一组坐标,我设法用背景颜色而不是描边填充了多边形.斯托克由于某种原因没有绘画吗?

My problem is that I'm drawing a set of coordinates on my wpf usercontrol with points, I managed to fill my polygon with background color but not with a stroke. Stoke for some reason is not drawing?

这是我使用DrawingContext在OnRender事件上的代码

Here is my code on the OnRender event using the DrawingContext

System.Windows.Media.Pen penDrawing = new System.Windows.Media.Pen(System.Windows.Media.Brushes.OrangeRed, 2);

                            drawingContext.DrawGeometry(System.Windows.Media.Brushes.LightSeaGreen, penDrawing, streamGeometry);

详细代码

StreamGeometry streamGeometry =新的StreamGeometry();

StreamGeometry streamGeometry = new StreamGeometry();

System.Windows.Point firstCoordinate = new System.Windows.Point();

System.Windows.Point lastCoordinateAdded = new System.Windows.Point();

bool isMainPolygon = true;

using (StreamGeometryContext geometryContext = streamGeometry.Open())
{
    PointCollection points = new PointCollection();

    firstCoordinate = new System.Windows.Point(coordinatePoints.ProjectedCoordinates[0].X, coordinatePoints.ProjectedCoordinates[0].Y);

    geometryContext.BeginFigure(firstCoordinate, true, true);

    System.Windows.Media.Pen penDrawing = new System.Windows.Media.Pen(System.Windows.Media.Brushes.OrangeRed, 5);

    penDrawing.EndLineCap = PenLineCap.Round;

    penDrawing.DashCap = PenLineCap.Round;

    penDrawing.LineJoin = PenLineJoin.Round;

    penDrawing.StartLineCap = PenLineCap.Round;

    penDrawing.MiterLimit = 10.0;

    for (int i = 1; i < coordinatePoints.ProjectedCoordinates.Count; i++)
    {
        lastCoordinateAdded = new System.Windows.Point() { X = coordinatePoints.ProjectedCoordinates[i].X, Y = coordinatePoints.ProjectedCoordinates[i].Y };

        points.Add(lastCoordinateAdded);

        //////Check to see if Polygon is done drawing
        if (firstCoordinate == lastCoordinateAdded)
        {
            geometryContext.PolyLineTo(points, true, true);

            //drawingContext.DrawGeometry(isMainPolygon ? System.Windows.Media.Brushes.Green : System.Windows.Media.Brushes.White, pen, streamGeometry);

            streamGeometry.Freeze();

            drawingContext.DrawGeometry(null, penDrawing, streamGeometry);

            points = new PointCollection();

            streamGeometry = new StreamGeometry();

            if (i + 1 < coordinatePoints.ProjectedCoordinates.Count)
            {
                i++;

                isMainPolygon = false;

                firstCoordinate = new System.Windows.Point(coordinatePoints.ProjectedCoordinates[i].X, coordinatePoints.ProjectedCoordinates[i].Y);

                geometryContext.BeginFigure(firstCoordinate, true, true);
            }
        }
    }

    geometryContext.PolyLineTo(points, true, true);
}

coordinatePoints.State = Enums.CoordinateEnum.None;

}

我很乐意提供更多详细信息.

I will glad to provide more details.

感谢一百万.

推荐答案

与所有内容一样,WPF缩放线的宽度,因此,如果笔划宽度相对于几何图形范围太窄,则笔划可能变得不可见.

As with everything, WPF scales the width of lines, so if the stroke width is too narrow relative to the extent of the geometry, the stroke can become invisible.

这篇关于WPF DrawGeometry不绘制笔触的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆