How can I have just the top corners rounded for a WPF rectange? I created a border and set the CornerRadius property and inside the border I've added my rectangle, but it doesn't work, the rectangle is not rounded.
<Border BorderThickness="1" Grid.Row="0" Grid.ColumnSpan="2" CornerRadius="50,50,0,0" BorderBrush="Black">
<Rectangle Fill="#FF5A9AE0" Grid.Row="0" Grid.ColumnSpan="2" Stretch="UniformToFill" ClipToBounds="True"/>
</Border>
This one will work even with Rectangle (or anything else) inside it:
You will have to play with Height and Width if you do not have exact size of content.
Good example how its possible to do OnRender with DrawingContext:
Information from: http://wpftutorial.net/DrawRoundedRectangle.html
Set the RadiusX and RadiusY properties on the rectangle, this will give it rounded corners
The problem you've got is that the rectangle is "overflowing" the rounded corners of your border.
A rectangle can't have individually rounded corners, so if you just put the background colour on the border and remove the rectangle:
You'll get your desired effect.