2012-08-31 145 views
5

QuadraticBezierSegment的末尾繪製箭頭的最簡單方法是什麼?棘手的部分是獲得正確的旋轉以加速進入的線段。使用xaml在二次貝塞爾曲線上繪製箭頭結尾

關於如何去做這件事的任何想法?我應該延長PathSegment嗎?

Bezier segment with an arrow at the end

我有了這個繪製簡單的貝賽爾曲線。

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

是您'QuadraticBezierSegment'靜態的'Path'? (它看起來像是從你的代碼中看到的,但你提到讓箭頭與該部分對齊,所以我不確定) – Rachel

+0

是的,它是靜態的,但是如果自動計算旋轉會很方便。 – vidstige

回答

8

您可以定義爲箭頭的形狀....但它會採取試錯正確定向它的貝塞爾曲線的末端。

相反,您可以使用此控件並使用幾何定義您想要的endcap,並將它正確放置在「行」的末尾。

  • http://blogs.msdn.com/b/mrochon/archive/2011/01/10/custom-line-caps-in-wpf.aspx

    <loc:CappedLine Stroke="Red" StrokeThickness="1" Canvas.Left="40" Canvas.Top="200" RenderTransformOrigin="0.5,0.5" Height="107" Width="195"> 
        <loc:CappedLine.EndCap> 
         <GeometryGroup> 
          <LineGeometry StartPoint="0,0" EndPoint="10,10"/> 
          <LineGeometry StartPoint="0,0" EndPoint="10,-10"/> 
         </GeometryGroup> 
        </loc:CappedLine.EndCap> 
        <loc:CappedLine.LinePath> 
         <PathGeometry Figures="M0,0 C1,1 10.5,75.5 48.5,66.5 86.5,57.5 5,3.5000146 105.5,16.500091 157.5,29.500166 164.5,87.500505 164.5,87.500505" /> 
        </loc:CappedLine.LinePath> 
    </loc:CappedLine> 
    
    <loc:CappedLine Stroke="Red" StrokeThickness="1" Canvas.Left="180" Canvas.Top="200" RenderTransformOrigin="0.5,0.5" Height="107" Width="195"> 
        <loc:CappedLine.EndCap> 
         <GeometryGroup> 
          <LineGeometry StartPoint="0,0" EndPoint="10,10"/> 
          <LineGeometry StartPoint="0,0" EndPoint="10,-10"/> 
         </GeometryGroup> 
        </loc:CappedLine.EndCap> 
        <loc:CappedLine.LinePath> 
         <PathGeometry Figures="M0,0 C1,1 10.5,75.5 48.5,66.5 86.5,57.5 5,3.5000146 105.5,16.500091" /> 
        </loc:CappedLine.LinePath> 
    </loc:CappedLine> 
    

enter image description here

相關問題