2011-12-10 2 views
0

wpf에서 경로를 사용할 때 새로운데 xaml 코드의 세그먼트를 C# 코드로 변환하는 방법을 모르겠습니다. 누군가가 이걸 도와 줄 수 있니? 나는 xaml 코드를 따라 간 다음 변환하려고 시도했다. C# 코드에는 무엇이 부족합니까? 내가 물어보고 싶은 또 하나의 점은 격자가 창에 표시 될 경로만큼이나 충분한 지 여부입니다. xaml을 C# 코드로 변환

<Path Stroke="Black" StrokeThickness="1"> 
<Path.Data> 
<PathGeometry> 
    <PathGeometry.Figures> 
    <PathFigureCollection> 
     <PathFigure StartPoint="10,100"> 
     <PathFigure.Segments> 
      <PathSegmentCollection> 
      <QuadraticBezierSegment Point1="200,200" Point2="300,100" /> 
      </PathSegmentCollection> 
     </PathFigure.Segments> 
     </PathFigure> 
    </PathFigureCollection> 
    </PathGeometry.Figures> 
</PathGeometry> 

내 C# 코드 :

Path myPath = new Path(); 
myPath.Stroke = Brushes.Black; 
myPath.StrokeThickness = 1 
PathGeometry myPathGeometry = new PathGeometry(); 
myPathGeometry.Figures = new PathFigureCollection(); 

PathFigure myPathFigure = new PathFigure(); 
myPathFigure.StartPoint = new Point(10, 100); 
myPathFigure.Segments = new PathSegmentCollection(); 
QuadraticBezierSegment theSegment = new QuadraticBezierSegment(); 
theSegment.Point1 = new Point(200, 200); 
theSegment.Point2 = new Point(100, 300); 
myPathFigure.Segments.Add(theSegment); 
myPathGeometry.Figures.Add(myPathFigure); 

답변

1

을 경로를 추가 그리고 당신은 X를 추가해야합니다 : 당신의 <Grid><Grid x:Name='myGrid'> 등으로 이름

그리고 하나 더 줄을 추가, 모양이 창에 표시되지 않습니다하지만

myGrid.Children.Add(myPath); 
+0

고마워, 알았다. 이미 데이터를 추가했지만 myGrid.Children.Add (myPath); – arjacsoh

0

귀하의 C# 코드가 WPF 마크 업처럼 많이 볼 수 있었다. . 다만, 당신은 마지막 행 다음에 추가해야 당신이 그것을 표시 할 컨트롤에

myPath.Data = myPathGeometry; 

var myPath = new Path 
{ 
    Stroke = Brushes.Black, 
    StrokeThickness = 1.0, 
    Data = new PathGeometry 
    { 
     Figures = new PathFigureCollection 
     { 
      new PathFigure 
      { 
       StartPoint = new Point(10, 100), 
       Segments = new PathSegmentCollection 
       { 
        new QuadraticBezierSegment 
        { 
         Point1 = new Point(200, 200), 
         Point2 = new Point(300, 100), 
        }, 
       }, 
      }, 
     }, 
    }, 
}; 
myGrid.Children.Add(myPath); 
+0

. xaml 파일에 만 있습니다. 뭐가 문제 야? 나는 어디에 경로를 추가해야 하는가? – arjacsoh

+0

그리드의 이름을 지정하고 경로를 추가하십시오. –