我希望這個問題以前沒有問過,我到處搜索。WPF DrawGeometry不畫筆劃
我的問題是,我正在用點繪製一組座標在我的wpf usercontrol上,我設法用背景色填充了我的多邊形,但沒有用筆畫。斯托克由於某種原因沒有繪製?
這是我在事件的OnRender代碼中使用的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();
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;
}
,我會很樂意提供更多的細節。
非常感謝。
這是OrangeRed,你沒有看到?爲什麼不使其尺寸超過2? – Rui
@Rui我想看看生成幾何的代碼。圖形細分是否設置爲撫摸? – Gusdor
幾何的範圍是什麼?我相信筆畫的寬度可能會縮小很多以適應它變得不可見的程度。 –