2012-11-05 94 views
0

我正在使用路徑來創建特定的形狀。將所有路徑分組的最佳方法是什麼,以便我可以稍後在另一個位置使用它們而無需重新定位路徑?如何在WPF中分組路徑?

任何建議都會很棒,謝謝!

回答

3

如果問題是關於只有一個填充和筆劃複雜的形狀,一個選項將僅使用一個具有PathGeometry和多個Figures的Path實例。請參閱MSDN中的以下示例:

<Path Stroke="Black" StrokeThickness="1"> 
    <Path.Data> 
     <PathGeometry> 
      <PathGeometry.Figures> 
       <PathFigureCollection> 
        <PathFigure IsClosed="True" StartPoint="10,100"> 
         <PathFigure.Segments> 
          <PathSegmentCollection> 
           <LineSegment Point="100,100" /> 
           <LineSegment Point="100,50" /> 
          </PathSegmentCollection> 
         </PathFigure.Segments> 
        </PathFigure> 
        <PathFigure IsClosed="True" StartPoint="10,10"> 
         <PathFigure.Segments> 
          <PathSegmentCollection> 
           <LineSegment Point="100,10" /> 
           <LineSegment Point="100,40" /> 
          </PathSegmentCollection> 
         </PathFigure.Segments> 
        </PathFigure> 
       </PathFigureCollection> 
      </PathGeometry.Figures> 
     </PathGeometry> 
    </Path.Data> 
</Path> 
1

您可以在畫布中分組,然後重新放置您的畫布。 命名每個路徑點將使您能夠修改形狀.... 您可以創建一個名爲MyOwnShape的新類,它繼承Canvas類,然後爲畫布的每個點附加一個事件以進行拖放操作形狀被修改。您也可以將您的內容放在燒烤架中,但無法以這種精度定位您的形狀。 如果我理解corectly你想要什麼achive.Your類應該looke這樣

class MyOwnShapes : Canvas { 

List<Path> myListOfPaths;
public void AddPath(Path myPath){ this.Children.Add(path); myListOfPaths.Add(path), // this is used for your internal computation so it wont affect the effective drawin components. }
我希望這個例子對你有好處。

http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh465055.aspx http://www.windowsphonegeek.com/tips/drawing-in-wp7-3-understanding-path-shapes