2014-02-13 112 views
0

我希望這個問題以前沒有問過,我到處搜索。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; 

}

,我會很樂意提供更多的細節。

非常感謝。

+0

這是OrangeRed,你沒有看到?爲什麼不使其尺寸超過2? – Rui

+0

@Rui我想看看生成幾何的代碼。圖形細分是否設置爲撫摸? – Gusdor

+0

幾何的範圍是什麼?我相信筆畫的寬度可能會縮小很多以適應它變得不可見的程度。 –

回答

0

與一切,WPF縮放線的寬度,因此,如果筆劃寬度是相對於所述幾何結構的程度太窄,行程可變得不可見。

0

創建幾何時,請確保在StreamGeometryContext.LineTo方法上設置stroked參數。

// Draw a line to the next specified point. 
ctx.LineTo(new Point(100, 100), true /* is stroked */, false /* is smooth join */); 
//        ↑ 
//        This parameter needs to be true. 
+0

我在方法中添加了代碼的全長,我沒有將PolyLineTo屬性IsStroked設置爲true。 – Ockert