我希望使用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>
它接近我想要的,但缺乏聯合功能。我需要合併重疊的形狀,以便只有1個輪廓存在。我曾嘗試使用2組幾何,其中1爲填充,1爲大綱,但在某些情況下,我需要填充爲透明,這使得此方法無效。 – 2011-05-03 04:43:33
@Ying - 您是否嘗試了FillRule屬性的不同選項?此外,如果失敗了,請檢查CombinedGeometry是否可以由其他CombinedGeometry對象組成。 – Gishu 2011-05-03 04:46:40
是的,CombinedGeometry可以由其他CombinedGeometry對象組成,但我不知道如何設置它,以便我可以簡單地將一個集合綁定到它。看到我編輯的問題 – 2011-05-03 04:49:20