2011-05-03 48 views
1

我希望使用Union將具有X,Y,Radius屬性的視圖模型集合綁定到組合幾何圖形。然而,CombinedGeometry似乎只支持2個幾何。WPF Multiple CombinedGeometry

反正有這個限制嗎?

是我的目標爲

<Path Stroke="Black" StrokeThickness="1" Fill="#CCCCFF"> 
    <Path.Data> 
    <CombinedGeometry GeometryCombineMode="Union" ItemsSource="{Binding Circles}"> 
     <CombinedGeometry.Template> 
     <EllipseGeometry RadiusX="{Binding Radius}" RadiusY="{Binding Radius}" CenterX="{Binding X}" CenterY="{Binding Y}"/> 
     </CombinedGeometry.Template> 
    </CombinedGeometry> 
    </Path.Data> 
</Path> 

這的確是可能的,如下圖所示有內CombinedGeometry CombinedGeometries的例子。但是,我不知道如何設置它以便輕鬆綁定。

<Path Stroke="Black" StrokeThickness="1" Fill="#CCCCFF"> 
     <Path.Data> 

     <!-- Combines two geometries using the union combine mode. --> 
     <CombinedGeometry GeometryCombineMode="Union"> 
      <CombinedGeometry.Geometry1> 
       <CombinedGeometry GeometryCombineMode="Union"> 
        <CombinedGeometry.Geometry1> 
         <EllipseGeometry RadiusX="50" RadiusY="50" Center="200,200" /> 
        </CombinedGeometry.Geometry1> 
        <CombinedGeometry.Geometry2> 
         <EllipseGeometry RadiusX="50" RadiusY="50" Center="125,200" /> 
        </CombinedGeometry.Geometry2> 
       </CombinedGeometry> 
      </CombinedGeometry.Geometry1> 
      <CombinedGeometry.Geometry2> 
       <CombinedGeometry GeometryCombineMode="Union"> 
        <CombinedGeometry.Geometry1> 
         <EllipseGeometry RadiusX="50" RadiusY="50" Center="100,100" /> 
        </CombinedGeometry.Geometry1> 
        <CombinedGeometry.Geometry2> 
         <EllipseGeometry RadiusX="50" RadiusY="50" Center="150,120" /> 
        </CombinedGeometry.Geometry2> 
       </CombinedGeometry> 
      </CombinedGeometry.Geometry2> 
     </CombinedGeometry> 
    </Path.Data> 
</Path> 

回答

0

您是否在尋找GeometryGroup

MSDN代碼示例:

<Path Stroke="Black" StrokeThickness="1" Fill="#CCCCFF">  
    <Path.Data> 
    <!-- Creates a composite shape from three geometries. --> 
    <GeometryGroup FillRule="EvenOdd"> 
     <LineGeometry StartPoint="10,10" EndPoint="50,30" /> 
     <EllipseGeometry Center="40,70" RadiusX="30" RadiusY="30" />   
     <RectangleGeometry Rect="30,55 100 30" /> 
    </GeometryGroup>  
    </Path.Data> 
</Path> 
+2

它接近我想要的,但缺乏聯合功能。我需要合併重疊的形狀,以便只有1個輪廓存在。我曾嘗試使用2組幾何,其中1爲填充,1爲大綱,但在某些情況下,我需要填充爲透明,這使得此方法無效。 – 2011-05-03 04:43:33

+0

@Ying - 您是否嘗試了FillRule屬性的不同選項?此外,如果失敗了,請檢查CombinedGeometry是否可以由其他CombinedGeometry對象組成。 – Gishu 2011-05-03 04:46:40

+0

是的,CombinedGeometry可以由其他CombinedGeometry對象組成,但我不知道如何設置它,以便我可以簡單地將一個集合綁定到它。看到我編輯的問題 – 2011-05-03 04:49:20

0

我有一種類似的問題,並在這裏發現了一個hepfull後: How to make the border trim the child elements?

你也可以嘗試創建接收集合在結合轉換器並根據需要構建組合幾何圖形。 我現在要做的就是:)

+0

其實我的問題已經通過'group.FillRule = FillRule.Nonzero ;' – Vittel 2012-04-25 12:28:55