2016-01-11 60 views
1

我想繪製一個形狀,這將是一個有許多圓孔的矩形。它應該看起來有點像連接四個遊戲板。我想知道是否可以繪製它沒有任何代碼隱藏助手或循環。WPF/XAML畫布中的可重複形狀

到目前爲止,我還做了一個元素:

<Canvas> 
     <Path Fill="Red"> 
      <Path.Data> 
       <CombinedGeometry GeometryCombineMode="Xor"> 
        <CombinedGeometry.Geometry1> 
         <RectangleGeometry Rect="0, 0, 60, 60" /> 
        </CombinedGeometry.Geometry1> 
        <CombinedGeometry.Geometry2> 
         <EllipseGeometry RadiusX="25" RadiusY="25" Center="30,30" /> 
        </CombinedGeometry.Geometry2> 
       </CombinedGeometry> 
      </Path.Data> 
     </Path> 
    </Canvas> 

是否有可能將多個該元素只有在XAML?

回答

1

您可以使用VisualBrush作爲Canvas的背景,並將幾何圖形指定爲畫筆的視覺。這裏是一個例子:

<Canvas Width="200" Height="200"> 
     <Canvas.Background> 
     <VisualBrush TileMode="Tile" Stretch="None" Viewport="0,0,0.35,0.35"> 
      <VisualBrush.Visual> 
      <Path Fill="Red"> 
       <Path.Data> 
       <CombinedGeometry GeometryCombineMode="Xor"> 
        <CombinedGeometry.Geometry1> 
        <RectangleGeometry Rect="0, 0, 60, 60" /> 
        </CombinedGeometry.Geometry1> 
        <CombinedGeometry.Geometry2> 
        <EllipseGeometry RadiusX="25" RadiusY="25" Center="30,30" /> 
        </CombinedGeometry.Geometry2> 
       </CombinedGeometry> 
       </Path.Data> 
      </Path> 
      </VisualBrush.Visual> 
     </VisualBrush> 
     </Canvas.Background> 
    </Canvas>