如何在 Silverlight/WPF 中反转剪裁几何?
Posted
技术标签:
【中文标题】如何在 Silverlight/WPF 中反转剪裁几何?【英文标题】:How to invert clipping geometry in Silverlight/WPF? 【发布时间】:2011-12-04 01:43:49 【问题描述】:UIElement.Clip
属性采用Geometry
对象并使用它来剪掉UIElement
的外部。我想做几何逆运算,然后在元素上打一个洞。
有人知道怎么做吗?
我想创建剪辑几何的倒置版本会起作用,但我找不到这样做的方法。
编辑 似乎 WPF 有 Geometry.Combine
可用于从另一个几何体中减去一个几何体,尽管这在 Silverlight 中不可用。如果是这样,我可以从元素的边界矩形的矩形中减去剪辑几何,然后用它来剪辑。
【问题讨论】:
【参考方案1】:Silverlight 中的一种方法是使用 GeometryGroup
并在组中包含一个从远处负位置开始的非常大的矩形。
例如下面的蓝色方块有较小的方孔:-
<Rectangle Fill="Blue" HorizontalAlignment="Center" VerticalAlignment="Center" Height="200" Width="200">
<Rectangle.Clip>
<GeometryGroup>
<RectangleGeometry Rect="-2048 -2048 4096 4096" />
<RectangleGeometry Rect="100 100 50 50" />
</GeometryGroup>
</Rectangle.Clip>
</Rectangle>
【讨论】:
以上是关于如何在 Silverlight/WPF 中反转剪裁几何?的主要内容,如果未能解决你的问题,请参考以下文章