2014-02-13 3 views
0

이 질문에 이전에 물어 보지 않았 으면 좋겠어.WPF DrawGeometry가 획을 그리지 않는다

내 문제는 점이있는 내 wpf usercontrol에서 좌표 집합을 그려야한다는 것입니다. 배경색을 사용하여 다각형을 채우지 만 스트로크는 채울 수 없었습니다. 어떤 이유로 스토킹이 그립지 않아? 여기

자세히

StreamGeometry streamGeometry = 새로운 StreamGeometry를

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); 

코드를 DrawingContext를 사용하여의 OnRender 이벤트에 내 코드()입니다;

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

관련 문제