Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF - Path/Geometry help - Strange shape

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>
</Path>
like image 581
jonathanpeppers Avatar asked Dec 22 '09 20:12

jonathanpeppers


1 Answers

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.

like image 161
itowlson Avatar answered Sep 20 '22 03:09

itowlson