突出显示或勾勒装饰层中的任何 UIElement
我希望能够以某种方式勾勒或突出显示装饰层中的任何特定 UIElement
(甚至可能是 Visual
)。装饰器本身不是问题。我更关心创建 UIElement
的轮廓。
我的目标是 OuterGlowBitmapEffect
提供类似的效果。我想遵循 UIElement
的外部轮廓。我尝试了很多方法来检查 Clip
属性(几乎总是 null)和其他一些方法,但我惨败了。
现在我想这肯定很容易,只是我错过了一些东西。此外,谷歌这次也不是我的朋友。
编辑:NET 3.5 是一个要求
I would like to be able to somehow outline or highlight any particular UIElement
(or perhaps even Visual
) in an adorner layer. Adorner is not a problem per se. I am more concerned about creating an outline of a UIElement
.
I am aiming at a similar effect that OuterGlowBitmapEffect
provides. I want to follow the outer contour of an UIElement
. I have tried many approaches with examining Clip
property (almost always null) and some other methods but I failed miserably.
Now I am thinking this must surely be easy it is just that I am missing something. In addition, Google was not my friend this time as well.
EDIT: NET 3.5 is a requirement
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将
OpacityMask
与VisualBrush
一起使用,并将其Visual
设置为您想要轮廓的元素。在下面的示例中,前景有一个Rectangle
,背景有一个TabControl
。由于选项卡控件不是矩形,我们可以看看该技术是否有效:结果如下所示:
仅突出显示选项卡控件及其选项卡标题。
You can use an
OpacityMask
with aVisualBrush
with itsVisual
set to the element you want the outline of. Here's an example where we have aRectangle
in the foreground and aTabControl
in the background. Since the tab control is not rectangular, we can see if the technique works:The result looks like this:
Only the tab control and its tab header are highlighted.
一种方法是重写
UIElement
的OnRender
,如 MSDN SimpleCircleAdorner 示例。如果您想在典型矩形或圆角矩形之外提供强大的解决方案,则必须使用 路径几何图形,它允许您构建由
BezierSegment
、LineSegment
或ArcSegment< 等线段组成的路径/code> 从而在
UIElement
周围创建适当的路径。另一方面,如果矩形或圆角矩形就足够了,您可以在
OnRender
中分别使用DrawingContext.DrawRectangle
和DrawingContext.DrawRoundedRectangle
覆盖。One way is to override the
OnRender
of theUIElement
as seen in the MSDN SimpleCircleAdorner example.If you want to provide a robust solution outside a typical rectangle or rounded rectangle you will have to make use of path geometries which will allow you to build out a path composed of segments such as a
BezierSegment
, aLineSegment
, or anArcSegment
thus creating an appropriate path around theUIElement
.If on the other hand a rectangle or rounded rectangle would suffice you can make use of the
DrawingContext.DrawRectangle
andDrawingContext.DrawRoundedRectangle
respectively within theOnRender
override.