WPF 矩形 - 圆化顶角
如何让 WPF 矩形的顶角变成圆角?
我创建了一个边框并设置了 CornerRadius 属性,并在边框内添加了矩形,但它不起作用,矩形不是圆角的。
<Border BorderThickness="1" CornerRadius="50,50,0,0" BorderBrush="Black">
<Rectangle Fill="#FF5A9AE0" Stretch="UniformToFill" ClipToBounds="True"/>
</Border>
How can I have just the top corners rounded for a WPF rectangle?
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" CornerRadius="50,50,0,0" BorderBrush="Black">
<Rectangle Fill="#FF5A9AE0" Stretch="UniformToFill" ClipToBounds="True"/>
</Border>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您遇到的问题是矩形“溢出”了边框的圆角。
矩形不能有单独的圆角,因此如果您只需将背景颜色放在边框上并删除矩形:
您将获得所需的效果。
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.
在矩形上设置 RadiusX 和 RadiusY 属性,这将给它圆角
Set the RadiusX and RadiusY properties on the rectangle, this will give it rounded corners
很好的例子,如何使用 DrawingContext 进行 OnRender:
信息来自:
http://wpftutorial.net/DrawRoundedRectangle.html
Good example how its possible to do OnRender with DrawingContext:
Information from:
http://wpftutorial.net/DrawRoundedRectangle.html
即使里面有矩形(或其他任何东西),这个也可以工作:
如果你没有内容的精确大小,你将不得不使用高度和宽度。
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.