自定义 WPF 折线的圆角半径
是否可以将 WPF 折线的角半径设置为自定义值。 对于 WPF 边框来说这是可能的。 在我看来,折线只能设置 StrokeLineJoin="Round",但不能设置半径:
<Polyline Points="0,0 0,100 200,100" StrokeLineJoin="Round" />
对于边框:CornerRadius="..." 是可能的:
<Border CornerRadius="8" ... />
是否有一个简单的解决方法/黑客来实现自定义角圆角(在线连接处)折线? (例如 Microsoft Visio 就可以做到这一点。) 谢谢!
is it possible to set the corner radius of a WPF polyline to a custom value.
For a WPF border it is possible.
In my opinion, the polyline can only set StrokeLineJoin="Round", but not the radius:
<Polyline Points="0,0 0,100 200,100" StrokeLineJoin="Round" />
For border: CornerRadius="..." is possible:
<Border CornerRadius="8" ... />
Is there an easy workaround/hack to achieve custom corner roundings (at line joins) of polylines?
(e.g. Microsoft Visio is able to do this.)
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
直接使用开箱即用的 WPF 中的可用内容是不可能的。然而,这是我编写的一段代码,它不是我所说的“简单的解决方法”,但它应该可以工作。在Xaml中,我认为声明应该是:
C#代码:
It's not possible directly with what's available in out-of-the-box WPF. However, here is a piece of code I cooked to do it, it's not what I would call "an easy workaround", but it should work. In Xaml, I think the declaration should be:
C# code:
我不知道,但他们是一个黑客......使用表达式混合创建带有角半径设置的边框或矩形,然后转换为路径?这将采用一个矩形(设置了角半径)并使其成为一条路径!
Not that I know of but their is a hack... create your border or rectangle with corner radius set using expression blend and then convert to path? This will take a rectangle (with a corner radius set) and make it a path!
为了任何可能需要它的人。我也在寻找支持圆角的 WPF Polygon 类。
我进一步构建了 Simon Mourier 的代码。
每个点都有自己的可选半径和全局半径。
For sake of whoever may need it. I was also in search of a WPF Polygon class that would support rounded corners.
I built further on the code of Simon Mourier.
Each point has their own optional radius, and a global one.
请参阅 http://www.charlespetzold.com/blog /2008/04/Rounded-Graphics-in-WPF.html 获胜。
See http://www.charlespetzold.com/blog/2008/04/Rounded-Graphics-in-WPF.html for the win.