Clip inverted own geometry

2019-08-17 18:38发布

问题:

Following Increase StrokeThickness but maintain dimensions of Path, is it possible to do the opposite? keeping only the outer stroke. Is there a way to exclude the self geometry?

回答1:

You may also clip the Path by its own geometry, but use a CombinedGeometry with a large enough outer RectangleGeometry and an excluded inner geometry, provided by the Path's Data:

<Path ...>
    <Path.Clip>
        <CombinedGeometry
            GeometryCombineMode="Exclude"
            Geometry2="{Binding Data, RelativeSource={RelativeSource AncestorType=Path}}">
            <CombinedGeometry.Geometry1>
                <RectangleGeometry Rect="-1000,-1000,2000,2000"/>
            </CombinedGeometry.Geometry1>
        </CombinedGeometry>
    </Path.Clip>
</Path>

Alternatively, you may perhaps draw a second, filled Path with the same geometry on top of the first one. You need to make sure both are aligned identically.

<Path x:Name="path" ...>
<Path Fill="White" Data="{Binding Data, ElementName=path}"/>