Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 多重组合几何法_Wpf_Binding_Geometry - Fatal编程技术网

Wpf 多重组合几何法

Wpf 多重组合几何法,wpf,binding,geometry,Wpf,Binding,Geometry,我希望使用Union将具有X、Y、半径属性的viewmodels集合绑定到圆的组合几何。然而,组合几何似乎只支持2种几何 这一限制是否存在 我的目标的例子 <Path Stroke="Black" StrokeThickness="1" Fill="#CCCCFF"> <Path.Data> <CombinedGeometry GeometryCombineMode="Union" ItemsSource="{Binding Circles}">

我希望使用Union将具有X、Y、半径属性的viewmodels集合绑定到圆的组合几何。然而,组合几何似乎只支持2种几何

这一限制是否存在

我的目标的例子

<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>

确实可以在组合几何中使用组合几何,如下所示。但是,我不知道如何设置它,使其易于绑定

   <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>

你在找什么

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>

我也有类似的问题,在这里找到了一篇完整的帖子:

您还可以尝试创建一个转换器,该转换器接收该绑定中的集合,并根据需要构建组合几何体。
我现在要做的就是:)

此代码生成的结果与OP的第二个代码相同:

<Path Stroke="Black" StrokeThickness="1" Fill="#CCCCFF">
    <Path.Data>
        <CombinedGeometry GeometryCombineMode="Union">
            <CombinedGeometry.Geometry1>
                <!-- any geometry here -->
                <GeometryGroup/>
            </CombinedGeometry.Geometry1>
            <CombinedGeometry.Geometry2>
                <GeometryGroup FillRule="Nonzero">
                    <EllipseGeometry RadiusX="50" RadiusY="50" Center="200,200" />
                    <EllipseGeometry RadiusX="50" RadiusY="50" Center="125,200" />
                    <EllipseGeometry RadiusX="50" RadiusY="50" Center="100,100" />
                    <EllipseGeometry RadiusX="50" RadiusY="50" Center="150,120" />
                </GeometryGroup>
            </CombinedGeometry.Geometry2>
        </CombinedGeometry>
    </Path.Data>
</Path>


您可以通过

中的
Children=“{Binding Circles}”
绑定到集合,而不是所有的
,这与我想要的很接近,但缺少union功能。我需要合并重叠的形状,以便只存在一个轮廓。我尝试使用两组几何体,一组用于填充,一组用于轮廓,但是在某些情况下,我需要填充透明,这使得此方法无效。@Ying-是否尝试了FillRule属性的不同选项?此外,如果这不起作用-检查CombinedGeometry是否可以由其他CombinedGeometry对象组成。是的,CombinedGeometry可以由其他CombinedGeometry对象组成,但我不知道如何设置它,以便我可以简单地将集合绑定到它。见我的编辑question@Ying-
我希望能够动态添加和删除将联合的圆圈。你能给我举个例子说明如何运用你的想法吗?实际上我的问题已经通过
group.FillRule=FillRule.Nonzero