开发者

WPF - Path/Geometry help - Strange shape

开发者 https://www.devze.com 2022-12-14 12:45 出处:网络
Anyone know a good way to create this object from Xaml?It also has to work at .5 Opacity when layered on top of other controls.

Anyone know a good way to create this object from Xaml? It also has to work at .5 Opacity when layered on top of other controls.

It also has to be resizable via Horizontal or Vertical Alignment.

I'm having some difficulty. The closest I get is with 2 borders, one having a negative margin--but it doesn't work when Opacity is applied.

Code that works:

<Path Fill="Black">
    <Path.Data>
        <CombinedGeometry GeometryCombineMode="Exclude">
            <CombinedGeometry.Geometry1>
                <RectangleGeometry RadiusX="5" RadiusY="5" Rect="0,0,200,100" />
            </CombinedGeometry.Geometry1>
            <CombinedGeometry.Geometry2>
                <RectangleGeometry RadiusX="5" RadiusY="5" Rect="105,5,90,90" />
            </CombinedGeometry.Geometry2>
        </CombinedGeometry>
    </Path.Data>
</Pat开发者_如何学Pythonh>


Use a GeometryGroup with an EvenOdd FillRule, or a CombinedGeometry with a GeometryCombineMode of Xor or Exclude. The geometries to combine will both be RectangleGeometry objects, with an appropriate RadiusX and RadiusY. The result will be the outer rectangle with a "hole" in it where the inner rectangle was located. (I assume this is what you want rather than a white rectangle within the black one.)

You can then assign this composite geometry to a Path as its Data property, and set the Fill and Opacity as required.

0

精彩评论

暂无评论...
验证码 换一张
取 消