Dot-Net
如何在 Silverlight/WPF 中反轉剪裁幾何?
該
UIElement.Clip屬性接受一個Geometry對象並使用它來剪掉UIElement. 我想做幾何逆運算並在元素上打一個孔。有人知道怎麼做嗎?
我想創建剪輯幾何的倒置版本會起作用,但我找不到這樣做的方法。
編輯似乎 WPF
Geometry.Combine可以用來從另一個幾何體中減去一個幾何體,儘管這在 Silverlight 中不可用。如果是這樣,我可以從元素的邊界矩形的矩形中減去剪輯幾何,然後用它來剪輯。
Silverlight 中的一種方法是使用 a
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>