Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inverted Corner Radius in WPF (something like a negative Radius)

I try to create a border with a negative Corner radius, like this:

enter image description here

I want the radius on the inside. Is this possible with build in functions or do I have to paint it with a path?

like image 981
Tokk Avatar asked Oct 04 '11 21:10

Tokk


People also ask

How do I round an image in WPF?

You can define a <Border/> element and set its <Border. Background/> property to an <ImageBrush/> , set the Borders CornerRadius property and you are all set!

Which property can be used to round the corners of an element?

The border-radius CSS property rounds the corners of an element's outer border edge. You can set a single radius to make circular corners, or two radii to make elliptical corners.

How do you change the corner radius of a storyboard?

Select the view that you want to round and open its Identity Inspector. In the User Defined Runtime Attributes section, add the following two entries: Key Path: layer. cornerRadius , Type: Number, Value: (whatever radius you want)


1 Answers

Well I faced the same problem and tried to figure out a solution. Last but not least I came to the conclusion that it is not possible to solve this with a border.

I focussed on drawing my Border with the Path and the CombinedGeometry function.

If anyone is still looking for a solution how to make inverted round corners here is my solution:

<Grid>
            <Path Stroke="Black" Fill="White" StrokeThickness="10" Stretch="Fill">
                <Path.Data>
                    <CombinedGeometry GeometryCombineMode="Exclude">
                        <CombinedGeometry.Geometry1>                                
                            <RectangleGeometry Rect="100,200 200,100"/>
                        </CombinedGeometry.Geometry1>
                        <CombinedGeometry.Geometry2>
                            <EllipseGeometry RadiusX="50" RadiusY="50" Center="300,300" />
                        </CombinedGeometry.Geometry2>
                    </CombinedGeometry>
                </Path.Data>
            </Path>
    <Button Margin="10" Height="10" Width="10"/>
</Grid>

You can resize the Rectanglewith changing the values in RectangleGeometry Rect="100,200 200,100and add inside it any other WPF item.. in this case I added a Button.

Here's the result:

Result screenshot

like image 160
Buddha1996 Avatar answered Nov 14 '22 11:11

Buddha1996